[comp.os.os2.programmer] '.cmd' return codes

tmeiners@ncratl.AtlantaGA.NCR.COM (Tedd Meinersmann) (04/11/91)

I would like to get a return code from a executable file (.cmd or .exe)
when I execute the file from within my 'C' code.

On a Unix system, this is not a problem since '/bin/sh' will return
the status of the last command executed or the return code given with
a shell 'exit' command.

For OS/2 (MicroSoft C 6.0) 'cmd.exe' does not return an exit status of
the '.cmd' or '.exe' file that it executed.  There is no 'exit' equivalent
of '.cmd' programming to force a return code.

Another problem (I think, but am not 100% sure of) is that the 'system'
procedure return a zero if the 'cmd.exe' is executed successfully and
non-zero if it isn't.  It does not return the return code it gets from
'cmd.exe' from the 'DosWait' procedure.

Does anyone have any ideas on how to overcome this problem?

Kludge solutions include (the child process being executed) writing to
a file, shared memory, pipe, semaphore, etc. and have the parent check
that output after the child is complete.

Anything better????

-- 
Tedd.Meinersmann@AtlantaGA.NCR.COM                           (404)-623-7349
2651 Satellite Blvd.
Duluth, GA  30136

GD.SAR@forsythe.stanford.edu (Sandy Rockowitz) (04/11/91)

In article <18503@ncratl.AtlantaGA.NCR.COM>,
tmeiners@ncratl.AtlantaGA.NCR.COM (Tedd Meinersmann) writes:
>I would like to get a return code from a executable file (.cmd or .exe)
>when I execute the file from within my 'C' code.
> [text deleted]
>
>For OS/2 (MicroSoft C 6.0) 'cmd.exe' does not return an exit status of
>the '.cmd' or '.exe' file that it executed.  There is no 'exit' equivalent
>of '.cmd' programming to force a return code.
>
Tedd,

If you are using IBM OS/2, you can use .CMD files written in Rexx.
Rexx allows you to set the return code.

Sandy Rockowitz
gd.sar@forsythe.stanford.edu

d88-pfo@dront.nada.kth.se (Peter Forsberg) (04/12/91)

In article <18503@ncratl.AtlantaGA.NCR.COM> tmeiners@ncratl.AtlantaGA.NCR.COM (Tedd Meinersmann) writes:

   I would like to get a return code from a executable file (.cmd or .exe)
   when I execute the file from within my 'C' code.

   [Text deleted]

If you want to execute .EXE programs this is not a problem, use DosExecPgm
with the wait option (alternatively with no wait, using DosCWait to check
the exit status of the child). For .CMD files you should use DosStartSession,
but I don't remember exactly how you fetch the return code. DosStartSession
has a *VAST* amount of options that you can specify.

   -- 
   Tedd.Meinersmann@AtlantaGA.NCR.COM                           (404)-623-7349
   2651 Satellite Blvd.
   Duluth, GA  30136

Peter Forsberg  (RIT & IBM Sweden)
--
_______________________________________________________________________________
Peter Forsberg 		      Royal Institute of Technology, Stockholm, Sweden.
Internet: d88-pfo@nada.kth.se
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~