473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

system() in the absence of a command processor

According to 7.20.4.5 of n869, system() can report whether the host
environment has a command processor (when passed a null pointer).
Obviously, if there is a command processor, non-null string arguments
to system() are passed to it. However, the text doesn't specifically
state what occurs when there is no command processor to pass strings
to. Presumably this is nothing, but should that be obvious from the
text?

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 19 '06 #1
9 2206
On Tue, 19 Sep 2006, Christopher Benson-Manica wrote:
According to 7.20.4.5 of n869, system() can report whether the host
environment has a command processor (when passed a null pointer).
Obviously, if there is a command processor, non-null string arguments
to system() are passed to it. However, the text doesn't specifically
state what occurs when there is no command processor to pass strings
to. Presumably this is nothing, but should that be obvious from the
text?
Undefined behavior (by omission).

Tak-Shing
Sep 19 '06 #2
Tak-Shing Chan <t.****@gold.ac.ukwrote:

(WRT to invoking system() when no command processor is available)
Undefined behavior (by omission).
Ah, right. So then

#include <stdlib.h>

int main(void)
{
if( system(NULL) )
system( "echo Hello world!" );
return 0;
}

is strictly conforming, but the alternative version without the
conditional is not? That's surprising, if only because even c.l.c.
regulars do not regularly point out such before invoking system() in
examples...

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 19 '06 #3
On Tue, 19 Sep 2006, Christopher Benson-Manica wrote:
Tak-Shing Chan <t.****@gold.ac.ukwrote:

(WRT to invoking system() when no command processor is available)
> Undefined behavior (by omission).

Ah, right. So then

#include <stdlib.h>

int main(void)
{
if( system(NULL) )
system( "echo Hello world!" );
return 0;
}

is strictly conforming, but the alternative version without the
conditional is not? That's surprising, if only because even c.l.c.
regulars do not regularly point out such before invoking system() in
examples...
Even if there is a command processor, system() might still
``behave in a non-conforming manner or to terminate'' (ISO
9899:1999, 7.20.4.6 para. 2), so it would be impossible to tell
whether your code above would invoke undefined behavior or not.

Tak-Shing
Sep 19 '06 #4
Christopher Benson-Manica wrote:
Tak-Shing Chan <t.****@gold.ac.ukwrote:

(WRT to invoking system() when no command processor is available)
Undefined behavior (by omission).

Ah, right. So then

#include <stdlib.h>

int main(void)
{
if( system(NULL) )
system( "echo Hello world!" );
return 0;
}

is strictly conforming, but the alternative version without the
conditional is not?
Any program that uses the system() function with a non-null argument is
probably not strictly conforming; a program that uses the system()
function to perform output certainly is not strictly conforming.

Robert Gamble

Sep 19 '06 #5
Tak-Shing Chan wrote:
Even if there is a command processor, system() might still
``behave in a non-conforming manner or to terminate'' (ISO
9899:1999, 7.20.4.6 para. 2), so it would be impossible to tell
whether your code above would invoke undefined behavior or not.
That sounds like undefined behavior to me!

--
Thad
Sep 20 '06 #6
Thad Smith <Th*******@acm.orgwrote:
Even if there is a command processor, system() might still
``behave in a non-conforming manner or to terminate'' (ISO
9899:1999, 7.20.4.6 para. 2), so it would be impossible to tell
whether your code above would invoke undefined behavior or not.
That sounds like undefined behavior to me!
It seems like it might be a bit disingenuous to simply call it
"undefined behavior", since the implementation must provide at least
some documentation for how system() will behave. Even the DS9K must
indicate that strings passed to system() will be passed to
evilCommandShell.exe for execution, although after that of course one
would be advised to seek shelter in a nuclear bunker.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 20 '06 #7
Robert Gamble <rg*******@gmail.comwrote:
Any program that uses the system() function with a non-null argument is
probably not strictly conforming; a program that uses the system()
function to perform output certainly is not strictly conforming.
I imagine you're right, since as soon as you invoke system() you're
heading to the implementation documentation to find out what will
happen. I suppose that if one doesn't know whether the implementation
provides a command processor, one probably doesn't have any business
invoking system() anyway.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 20 '06 #8
Christopher Benson-Manica <at***@ukato.freeshell.orgwrote:
Thad Smith <Th*******@acm.orgwrote:
Even if there is a command processor, system() might still
``behave in a non-conforming manner or to terminate'' (ISO
9899:1999, 7.20.4.6 para. 2), so it would be impossible to tell
whether your code above would invoke undefined behavior or not.
That sounds like undefined behavior to me!

It seems like it might be a bit disingenuous to simply call it
"undefined behavior", since the implementation must provide at least
some documentation for how system() will behave. Even the DS9K must
indicate that strings passed to system() will be passed to
evilCommandShell.exe for execution, although after that of course one
would be advised to seek shelter in a nuclear bunker.
Yes, but what system() actually _does_ is undefined. Or rather, what the
program called by system() does is. And it must be, because that can be
useful.
For example, you might call system("viruschecker -checkfile:
receivedexecutable"), and the user might have configured his virus
checker not to do anything by default, but always to ask him whether to
[S]kip this file, [D]elete it, or [T]erminate the calling program with
extreme prejudice. If he chooses option [T], *poof* goes your program in
a display of highly undefined - by the Standard, that is! - behaviour.

Thus, only part of what system() does - call a command shell with a
certain command line - is defined. The other part - what that command
shell does with this line - cannot, and should not even if it could, be
defined by the ISO C Standard.

Richard
Oct 3 '06 #9
Richard Bos wrote:
Christopher Benson-Manica <at***@ukato.freeshell.orgwrote:
Thad Smith <Th*******@acm.orgwrote:
Even if there is a command processor, system() might still
``behave in a non-conforming manner or to terminate'' (ISO
9899:1999, 7.20.4.6 para. 2), so it would be impossible to tell
whether your code above would invoke undefined behavior or not.
That sounds like undefined behavior to me!
It seems like it might be a bit disingenuous to simply call it
"undefined behavior", since the implementation must provide at least
some documentation for how system() will behave. Even the DS9K must
indicate that strings passed to system() will be passed to
evilCommandShell.exe for execution, although after that of course one
would be advised to seek shelter in a nuclear bunker.

Yes, but what system() actually _does_ is undefined. Or rather, what the
program called by system() does is. And it must be, because that can be
useful.
The behaviour is only undefined if this documentation states the
behaviour is undefined. As an example, it's possible and in some cases
even reasonable that implementation-specific documentation for system()
includes descriptions of shell built-in commands. If it does, they are
required to behave as documented.

Oct 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
6
by: JLK | last post by:
I'm having a bit of a time with the following code. I can script this real easy in Bash but I'm trying to practice my C++: ******************************************************* #include...
5
by: KevinGPO | last post by:
What's the difference between system("myGame.exe"); and system("start myGame.exe"); ?
10
by: Vavel | last post by:
Hi all! I want to insert the record into the table by using an application program that includes the following statements: EXEC SQL BEGIN DECLARE SECTION; long hvInt_Stor; long hvExt_Stor;...
2
by: Sara Shoemaker | last post by:
Hi all - I am trying to launch a web browser from within my code for Linux. The problem is that I am getting no failure code back when the browser doesn't launch. (I'm trying to force a failure...
11
by: jobs239 | last post by:
Can I use this line inside C program "system(java -jar <jarfilename>)" to run a java program from C? Or do I have to use some JNI interface.?
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
12
by: Bob | last post by:
Howdy, Why does a call to system() work by passing the command line string supplied to sh -c? This is causing problems when running in a chroot environment where no sh is available. Wouldn't it...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.