Re: Use of System function
- From: "Rod Pemberton" <do_not_have@xxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Mar 2006 20:16:17 -0500
"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:lnr74m12qb.fsf@xxxxxxxxxxxxxxxxxx
"Rod Pemberton" <do_not_have@xxxxxxxxxxxxxxxxx> writes:'\'
"osmium" <r124c4u102@xxxxxxxxxxx> wrote in message
news:48slglFlp6maU1@xxxxxxxxxxxxxxxxx
"Ralph A. Moritz" writes:
BHARAT MEHTA wrote:
Hi Guys,
I am little new to C. I wish to know the way to use the 'system'
function. I mean I know that the function is used to run an external
DOS command but every time I use it it returns -1 which meansthe
command could not be executed.
system() uses the shell (COMMAND.COM on DOS/Windows, /bin/sh
on Unix) to execute the specified command. If you just give a program
name such as `unzip', then `unzip' must be in a directory specfied in
the PATH environment variable. To be sure, use an absolute path to
the executable, eg.
system("/usr/games/fortune");
system("C:\Program Files\Winzip\wzip32.exe");
If that second one doesn't work check up on escape sequences WRT the
system()character..
The second one does work and is correct for MS-DOS. The string in
passed directly to the OS's command processor _AS_IS_. For the MS-DOS
command.com command line, one does not need to escape the backslash '\'
character as you would for printf().
Wrong. (Did you actually try it?)
I have existing code which does the same thing (which I which consulted
prior to my post). No escapes are needed and it works with multiple DOS
based compilers.
The argument to system() is a string literal, and is interpreted
according to C's rules for string literals. The fact that it's an
argument to system() is irrelevant.
Apparently not. I haven't checked the ISO spec., but Harbison and Steele
agrees with me that the string from system() is passed as is to the OS in an
implementation defined manner.
.
- Follow-Ups:
- Re: Use of System function
- From: Jordan Abel
- Re: Use of System function
- References:
- Use of System function
- From: BHARAT MEHTA
- Re: Use of System function
- From: Ralph A. Moritz
- Re: Use of System function
- From: Rod Pemberton
- Re: Use of System function
- From: Keith Thompson
- Use of System function
- Prev by Date: Re: returning char arrays from a function
- Next by Date: Re: Use of System function
- Previous by thread: Re: Use of System function
- Next by thread: Re: Use of System function
- Index(es):
Relevant Pages
|