Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Batch, Powershell, What Is It Really For?

batch powershell script shell

  • Please log in to reply
6 replies to this topic

#1 abderrahim

abderrahim

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts
  • Location:algeria
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell

Posted 30 June 2012 - 01:37 AM

Hi everybody,
I know that batch, powershell, perl... are script languages, what I don't know is if it's possible to use a lower level language as C instead, even if it's hard, is it possible theoricaly??, or they are part of the operating system interface??, because I can't imagine how C language can kill a process (can we??),
I really hope to hearing the answer soon...
thank you in advence...
  • 0

#2 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 472 posts
  • Location:DarkSide

Posted 30 June 2012 - 06:50 AM

You are asking if C can terminate a process? or asking if you can use batch, powers, perl for your work?
  • 0
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#3 abderrahim

abderrahim

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts
  • Location:algeria
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell

Posted 30 June 2012 - 11:44 AM

thank you papabear!!
to be clear, the question is: can C language do what thoses script languages do? the opposite isn't true, I'm sure, if yes, can someone put some code that shutdown computer, terminate a process, hide folder or anything else....??
thank you
  • 0

#4 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 472 posts
  • Location:DarkSide

Posted 30 June 2012 - 01:33 PM

thank you papabear!!
to be clear, the question is: can C language do what thoses script languages do? the opposite isn't true, I'm sure, if yes, can someone put some code that shutdown computer, terminate a process, hide folder or anything else....??
thank you


yes.. you can actually call Batch or DOS Commands into C
and the code depends on what operating system you are using
here are some example shutdown

For Windows


#include <stdio.h>
#include <stdlib.h>

main()
{
   char ch;

   printf("Do you want to shutdown your computer now (y/n)\n");
   scanf("%c",&ch);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -s");

   return 0;
}


For Linux


#include <stdio.h>

int main() {
  system("shutdown -P now");
  return 0;
}

basically the system(); function accepts executable/shell built-ins and arguments.. in this code we are calling shutdown.exe
and giving it some arguments which you can also do in DOS/CMD. I know there is some good way of shutting down a computer
in C but this is my simplest way and example to give you answer that C is a powerful language and can do the job what those scripts can.
Happy Coding :)
  • 1
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#5 abderrahim

abderrahim

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts
  • Location:algeria
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell

Posted 30 June 2012 - 01:47 PM

thank you so much papabear; it helps a lot
  • 0

#6 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 30 June 2012 - 10:33 PM

C cannot shut down the operating system as intended on its own. It requires either an interface, API (for example, Windows .NET framework may include diagnostic namespaces for functions to shut down the computer) or through another process, such as invoking a command or executable to shut down the operating system, or through other means.

Scripting languages usually do not have such features built in, there is nothing inherently special about them and C can do such with only a little more effort,

Alexander.
  • 1

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#7 abderrahim

abderrahim

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 58 posts
  • Location:algeria
  • Programming Language:C, Java, PHP, Perl, Pascal, Assembly, Haskell
  • Learning:C, Java, PHP, JavaScript, PL/SQL, Assembly, Haskell

Posted 01 July 2012 - 01:40 AM

... It requires either an interface, API (for example, Windows .NET framework may include diagnostic namespaces for functions to shut down the computer) or through another process, such as invoking a command or executable to shut down the operating system, or through other means...
Alexander.

...basically the system(); function accepts executable/shell built-ins and arguments.. in this code we are calling shutdown.exe
and giving it some arguments which you can also do in DOS/CMD...

this clarifies it all,
thank you both Alexander and papabear
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download