delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/09/18/18:45:30

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Message-ID: <414c1225$0$177$cc7c7865@news.luth.se>
From: Martin Str|mberg <ams AT speedy DOT ludd DOT ltu DOT se>
Subject: Re: Problem using system( )
Newsgroups: comp.os.msdos.djgpp
References: <f7d84cf3 DOT 0409180201 DOT 713ca0b7 AT posting DOT google DOT com>
User-Agent: tin/1.4.6-20020816 ("Aerials") (UNIX) (NetBSD/1.6Q (alpha))
Date: 18 Sep 2004 10:47:01 GMT
Lines: 64
NNTP-Posting-Host: speedy.ludd.ltu.se
X-Trace: 1095504421 news.luth.se 177 130.240.16.13
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

anonymous <iunknown2k4 AT yahoo DOT co DOT in> wrote:
> I read the documentation for the system() function and I could understand
> that if the COMMAND.COM is used then it will always return 0, even if
> the command did not execute.

> I want to know whether the command passed to the system()
> was successfully run or not.

You can't if COMMAND.COM is invoked as you seem to understand from
above. You might be helped by "info libc a spawn".

> I am not able to understand
> the following:
>  
> "The behavior of `system' can be customized at run time by defining the
> variable `DJSYSFLAGS' in the environment.  The value of that variable
> should be the numerical value of `__system_flags' that you'd like to
> set; it will override the value of `__system_flags' specified when the
> program was compiled."

> Does it mean that the `DJSYSFLAGS' should be defined something like 

> #define DJSYSFLAGS  (  __system_emulate_command | __system_use_shell \
>                                   |__system_call_cmdproc)

No. It means you should set the environment variable "DJSYSFLAGS" to
the numerical value of the flags you want enabled (0x20, 0x4, 0x2)
ored together. I. e. you want to do "set DJSYSFLAGS 0x26". (I've never
used this so I might be wrong, but this is what I conclude from the
manual. )

> Also the return value is in the lower 8 bits, 
> so I'm checking it like

> struct retVal
>  {
>   char  r[2];
>  }*ret;

> ...

> int temp = system(cmd);
> ret = (struct retVal *) &temp;
> printf ("\n %d %d", ret->r[0], ret->r[1]);

IMHO, that casting is pretty bad C. Try:

int child_exit, child_signal;
int temp = system(cmd);
child_exit = temp&0xff;
child_signal = (temp&0xff000) >> 8;
printf ("\n %d %d", child_exit, child_signal);

instead. The above is UNTESTED.

> But, the vales are always zero even for system() called with
> an invalid command.

You might be better servered by spawn().


Right,

						MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019