Re: How to get the return code from a Unix command in Cobol
- From: Robert <no@xxxxxx>
- Date: Tue, 15 Jan 2008 22:12:40 -0600
On Tue, 15 Jan 2008 17:59:21 -0800 (PST), Richard <riplin@xxxxxxxxxxxx> wrote:
On Jan 16, 2:11 pm, Robert <n...@xxxxxx> wrote:
On Mon, 14 Jan 2008 23:40:29 -0800 (PST), Richard <rip...@xxxxxxxxxxxx> wrote:
I think that your whole rant has been wasted.
I just tested CALL "SYSTEM" and CALL "system" with and without a
RETURNING Result. In all cases I got the correct expected result in
Result or RETURN-CODE. It was zero if the command worked and non-zero
(granted byte order mangled) if it failed. There is no need (in my
tests) for any "exit &?".
I tested using CALL "SYSTEM|system" USING "sh do.sh" &
x"00" [RETURNING Result]
do.sh was:
#!/bin/sh
ls /xyz
as /xyz was missing it returned 2 (as 512).
I don't know what you did wrong in your tests but you seem to have
misdiagnosed the problem and provided a 'solution' to a non-problem.
I tried similar and also got the return code back. But some commands return zero until I
add an explicit exit. It acts as though a null command -- ;: or ;; -- is being added.
Perhaps because you failed to add the null terminator and some sort of
null command _was_ added.
That's possible. I would expect random bytes to be an invalid parameter.
When I call 'system' using 'echo abc', there are no extra bytes at the end.
Maybe your actual test had an 'echo &?' so you could see the value,
after which the return was bound to be zero.
I'm not that stupid.
Perhaps adding the 'exit &?' changed length of the string and what
characters followed it.
Anything following exit is irrelevant.
I tried your CALL "system" USING "test -d ..." and it worked exactly
as expected.
Thanks for trying it. I'm puzzled as to why it didn't work for me.
So that was three, which counts as 'several'.
The point about overwriting the file before the CALL "SYSTEM" is that
if the CALL fails, or the SYSTEM fails, or the command file fails,
then the program will not pick up the previous 'result file' which may
still contain 'success'.
These failure safeguards should be readily understood by someone who
is no longer a newbie.
I'd rather have 'looks ugly' than your 'does ugly' anyday.
My solution detects all those exceptions.
How so ?
All those failures, except the first, return a non-zero return code.
In the unlikely event call 'system' fails, Cobol will abort both unless the call contains
an ON EXCEPTION clause.
I was actually asking how it did this after you had taken my 'ugly'
code and made it 'pretty' with your so-called 'symmetric solution':
RW> The only suggestion was ugly: overwriting a file. I
RW> say ugly because it was asymmetric.
RW> The parent Cobol program wrote 'failure' and the
RW> child make overwrote it with 'success'.
RW> A symmetric solution would look like this:
RW> program: program.cbl; \
RW> cob program \
RW> && echo 'success' >$ myfile \
RW> || echo 'failure' > $myfile
This doesn't have the same functionality.
I left out the Cobol program:
select myfile assign to external '$myfile' file status file-status.
call 'system' using 'export myfile=`mktemp`' & x'0'
call 'system' using 'make' & x'0'
open input myfile
if file-status not less than '10'
move 'make error' to compilation-result
else
read myfile into compilation-result
at end move 'result empty' to compilation-result
end-read
end-if
close myfile
delete file myfile
if compilation-result not = 'success'
display 'compilation result is ' compilation-result
exit program returning 4
end-if
.
- Follow-Ups:
- References:
- Re: How to get the return code from a Unix command in Cobol
- From: Robert
- Re: How to get the return code from a Unix command in Cobol
- From: Richard
- Re: How to get the return code from a Unix command in Cobol
- From: Robert
- Re: How to get the return code from a Unix command in Cobol
- From: Richard
- Re: How to get the return code from a Unix command in Cobol
- From: Robert
- Re: How to get the return code from a Unix command in Cobol
- From: Richard
- Re: How to get the return code from a Unix command in Cobol
- From: Robert
- Re: How to get the return code from a Unix command in Cobol
- From: Richard
- Re: How to get the return code from a Unix command in Cobol
- Prev by Date: Re: COBOL and DB2 vs. Java and DB2
- Next by Date: Re: OT: Racial superiority / Intelligent design was Re: OT:Thanksgiving
- Previous by thread: Re: How to get the return code from a Unix command in Cobol
- Next by thread: Re: How to get the return code from a Unix command in Cobol
- Index(es):
Relevant Pages
|