Re: Use of System function




"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
'\'
character..

The second one does work and is correct for MS-DOS. The string in
system()
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.



.



Relevant Pages

  • Re: Creation of DSN
    ... Build a text string from the input data. ... rather execute the string that was just built. ... script file has been processed. ... > I'm using directly a Command, ...
    (microsoft.public.vb.database.ado)
  • Re: SET IDENTITY_INSERT tablename ON problem
    ... Try to combine all statements into one string and then execute them in one ... A couple of my tables use identity columns. ... > The next command is to insert the data but I get an error that says I ...
    (microsoft.public.vb.database.ado)
  • Re: Use of System function
    ... DOS command but every time I use it it returns -1 which meansthe ... If that second one doesn't work check up on escape sequences WRT the ... You _always_ need to escape the backslash when it appears in a string ... token has had escapes substituted for control characters. ...
    (comp.lang.c)
  • Re: Executing "unknown" command line in C#
    ... > fresh copy of the XML file. ... I have a string that needs to be ... And it works fine if you execute it from a DOS box, ... > my problem - to do this, I have to divide my command line into two ...
    (microsoft.public.dotnet.csharp.general)
  • Re: Scheduled tasks in WP
    ... The log rolls around so the end of the file is probably not where the logging stopped last. ... Have you tried running the string you entered in the Command field for the event? ... Is the RunAs for the event the same account under which you say the scheduled task will execute okay when started manually? ...
    (microsoft.public.windowsxp.general)