Mail Archives: djgpp/2004/09/18/23:30:24.1
On 18 Sep 2004 10:47:01 GMT in comp.os.msdos.djgpp, Martin Str|mberg
<ams AT speedy DOT ludd DOT ltu DOT se> wrote:
>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. )
Or:
#include <stdlib.h>
__system_flags |= __system_emulate_command
| __system_use_shell
| __system_call_cmdproc;
But I don't think this is what you want;
if you have a Unix shell (e.g. SHELL=bash), you should use:
__system_flags |= __system_use_shell
| __system_call_cmdproc; /* use shell */
__system_flags &= ~__system_emulate_command; /* clear emulation */
but if you want system() to avoid the shell, you should use:
__system_flags |= __system_emulate_command; /* emulation */
__system_flags &= ~(__system_use_shell
|__system_call_cmdproc); /* don't use shell */
>> 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);
if (temp == -1)
{
perror( cmd );
exit( # );
}
>child_exit = temp&0xff;
>child_signal = (temp&0xff000) >> 8;
ITYM:
child_signal = (temp & 0x3ff00) >> 8; /* bits 8-17 */
>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().
Note that unzip32 (unzip from info-zip) does not document any return
codes, so you might have to download and check out the source to see
if any meaning can be inferred from any of the return codes.
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian DOT Inglis AT CSi DOT com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
- Raw text -