Google Groups Home
Help | Sign in
Running (invoking) a windows cmd command within C code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
thomaskog...@gmail.com  
View profile
 More options Jul 8, 3:29 pm
Newsgroups: comp.lang.c.moderated
From: thomaskog...@gmail.com
Date: Tue, 8 Jul 2008 14:29:44 -0500 (CDT)
Local: Tues, Jul 8 2008 3:29 pm
Subject: Running (invoking) a windows cmd command within C code
Hello all,

I searched both the web and a couple usenet groups before posting this
here.

I am not proficient in C, I am just fooling around.  I need to find a
way to invoke a windows cmd command, namely shutdown, from within a C
program. I could only find stuff regarding C# or other languages..

In case you 're wondering, I frequently used to leave internet radio
on before going to sleep, setting my old XP PC to shutdown usually
after half an hour.. The command was something like shutdown /s /t
1800 (in sec).

Now I got a vista PC, and bloody microsoft decided to limit the
allowed time to 10 mins, or 600 seconds. Why the hell they bothered to
change that of all things is very weird, but anyway, I was thinking of
writing a simple C program that would take input from the user, for
example x seconds, 'sleep' for x-600 seconds, and then invoke
'shutdown /s /t 600'.

It will make my day, so any help is appreciated..
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Schwarz  
View profile
 More options Jul 10, 2:01 pm
Newsgroups: comp.lang.c.moderated
From: Barry Schwarz <schwa...@dqel.com>
Date: Thu, 10 Jul 2008 13:01:58 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:01 pm
Subject: Re: Running (invoking) a windows cmd command within C code

Look up the system() function in your C reference.

Remove del for email
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack Klein  
View profile
 More options Jul 10, 2:02 pm
Newsgroups: comp.lang.c.moderated
From: Jack Klein <jackkl...@spamcop.net>
Date: Thu, 10 Jul 2008 13:02:01 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:02 pm
Subject: Re: Running (invoking) a windows cmd command within C code
On Tue, 8 Jul 2008 14:29:44 -0500 (CDT), thomaskog...@gmail.com wrote
in comp.lang.c.moderated:

The part about sleeping is not provided by standard C, and requires a
Windows API call.  You need to ask about that in a Windows programming
group, news:comp.os.ms-windows.programmer.win32 is a good one.  Or you
could try searching Microsoft's MSDN site.

As for passing a string to the command interpreter, there is a
standard C function for that.

#include <stdlib.h>

int main(void)
{
   system("shutdown /s /t 600");
   return 0;

}

....should generally do the same thing as typing the command on a
command line.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francis Glassborow  
View profile
 More options Jul 10, 2:02 pm
Newsgroups: comp.lang.c.moderated
From: Francis Glassborow <francis.glassbo...@btinternet.com>
Date: Thu, 10 Jul 2008 13:02:20 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:02 pm
Subject: Re: Running (invoking) a windows cmd command within C code

check out 'system()' I think that will meet your requirements.
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cervello_in_vacanza  
View profile
 More options Jul 10, 2:02 pm
Newsgroups: comp.lang.c.moderated
From: cervello_in_vacanza <ale...@alice.it>
Date: Thu, 10 Jul 2008 13:02:23 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:02 pm
Subject: Re: Running (invoking) a windows cmd command within C code

In your program #include the <stdlib.h> header file and call any system
command from within the system() function:

        int system(const char *command);

The value returned from system() is -1 on error or the return status
of the command otherwise.

the character string command is the name of the system command you whish
to call.

To make an example if you want to blank the screen of the console you
should call:

system("cls");

and if you want to shut down after 60 seconds your computer call:

system("shutdown /s /t 60");

As far as I know, that's the sole way to make an OS
call without being forced to implement any Assembly code.

remember well that doing so, you bound your program to the OS it
was implemented for, because "cmd" or "shutdwn" are  MS Windows
commands.

regards,

cervello_in_vacanza
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jasen Betts  
View profile
 More options Jul 10, 2:02 pm
Newsgroups: comp.lang.c.moderated
From: Jasen Betts <ja...@xnet.co.nz>
Date: Thu, 10 Jul 2008 13:02:46 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:02 pm
Subject: Re: Running (invoking) a windows cmd command within C code
On 2008-07-08, thomaskog...@gmail.com <thomaskog...@gmail.com> wrote:

> Hello all,

> I searched both the web and a couple usenet groups before posting this
> here.

> I am not proficient in C, I am just fooling around.  I need to find a
> way to invoke a windows cmd command, namely shutdown, from within a C
> program. I could only find stuff regarding C# or other languages..

system("shutdown");

or ask in a windows programming newsgroup.

> Now I got a vista PC, and bloody microsoft decided to limit the
> allowed time to 10 mins, or 600 seconds. Why the hell they bothered to
> change that of all things is very weird, but anyway, I was thinking of
> writing a simple C program that would take input from the user, for
> example x seconds, 'sleep' for x-600 seconds, and then invoke
> 'shutdown /s /t 600'.

something like that could be done in batch, ping can be abused to
provide a timer....

Bye.
   Jasen
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth Brody  
View profile
 More options Jul 10, 2:02 pm
Newsgroups: comp.lang.c.moderated
From: Kenneth Brody <kenbr...@spamcop.net>
Date: Thu, 10 Jul 2008 13:02:59 -0500 (CDT)
Local: Thurs, Jul 10 2008 2:02 pm
Subject: Re: Running (invoking) a windows cmd command within C code
thomaskog...@gmail.com wrote:

[...]
> In case you 're wondering, I frequently used to leave internet radio
> on before going to sleep, setting my old XP PC to shutdown usually
> after half an hour.. The command was something like shutdown /s /t
> 1800 (in sec).

[...]

Use the system() function:

    int system(const char *string);

For example:

    system("shutdown /s /t 1800");

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamT...@gmail.com>
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google