Re: backtick and system return different exit codes
- From: meenal_binwade@xxxxxxxxxxxxxx
- Date: 27 Dec 2005 05:41:14 -0800
Tim Hammerquist wrote:
> meenal_binwade@xxxxxxxxxxxxxx <meenal_binwade@xxxxxxxxxxxxxx> wrote:
> > I am sure that the command is executed when i run it in
> > backticks cause it is returning the correct output.
> >
> > I am not really interested in knowing the exact error code.i
> > want to know whether the command executed successfully.
> > i guess i can safely do this as follows:
> >
> > my $do = `$cmd`;
> > if( $?)
> > {
> > print " command failed \n";
> > print "output is $do\n";
> > }
> > else
> > {
> > print "output is $do\n";
> > }
> >
> > print "\nexecuting system\n";
> > my $rc = system($cmd);
> > print "rc = $rc\n";
> > if($rc)
> > {
> > print " command failed \n";
> > }
> > else
> > {
> > print "command succeeded\n";
> > }
> >
> > //end of script
>
> You're still not adjusting the value of $? to get the actual
> return code from the ``/system() calls. Again, $? contains more
> than just the simple value after the "return" keyword of your
> C program!
>
> > The output looks like this:
>
> No it doesn't. Where's the "output is ..." information the
> if/else structure following the backtick operation?
>
> This code is still not a standalone piece of code which other
> people may run to see the output you describe. The code you
> provide, in addition to being incomplete, cannot produce the
> exact output you describe below.
>
> > command failed
> > myhost.com
> >
> > executing system
> > myhost.com
> > rc = 0
> > command succeeded
> >
> > //end of output
> >
> >
> > The wierd thing is if i run the same command in a shell or in
> > a perl script using system it prints the correct output and
> > also returns me an exit code of 0.
>
> You have not *once* told us what the value of $cmd is, so we can
> hardly reproduce this.
>
> > FYI I have done an explicit return 0 at the end of my program
> > ( $cmd in the example above is a c program).i have printed the
> > return value before the return statement in my main function
> > .I can see that a 0 is returned from the program when i run it
> > in backticks but somehow $? is showing me a value of -1.It
> > should have given me a value of 0 cause the command executed
> > successfully .
>
> This is simply not true. You have never once, in any code
> you've posted here, check that the return value of the external
> program was 0. You have only checked that the value of $? is 0.
> This is *not* the same thing.
>
> Please respond with actual *full* code which demonstrates the
> behavior, according to the posting guidelines. Please post code
> that makes correct use of the $? variable. Please post code
> that doesn't use the return value of one function to determine
> the success of a different function.
>
> Tim Hammerquist
Tim,
I cannot paste the code for $cmd program cause it is confidential and
it links with lots of other libraries in my project.
I modified my perl script to print the exit code as :
$do = `$cmd`;
print 'ec = ', $? >> 8, "\n";
$rc = system($cmd);
print 'ec = ', $? >> 8, "\n";
the first print statement at time gives this : ec = 72057594037927935
and the second always gives this : ec = 0
so the problem is that when my program is executed in bacticks at times
does not give the correct exit code(i am sure that the command is
executed in bacticks cause i get the correct output ) but when execute
using system never gives incorrect exit code .
And this is happening only on one particular linux machine whoes
configuration i mentioned before.
I am using pthreads in my program.Also my main function does not join
on all the threads it creates.
I wrote 2 sample programs. One in which main thread joins on the
threads it creates and the other in which it does not.
The first one when executed in bacticks gives the same exit code
(72057594037927935)
but gives 0 exit code when executed throught system .This is again
happening only on that particular linux machine.I did not see any exit
code problems on any other machine(solaris , linux.AIX etc)
The second sample program never returned exit code (72057594037927935)
when executed in backticks
I feel there is some problem with that particular linux machine.cause i
dont this happening on any other machine. or it is a known fact that
when main thread does not join on the threads it creates , there could
be something wrong in the exit code of the program( mind you the exit
code is correct always when executed through system).
.
- References:
- backtick and system return different exit codes
- From: meenal_binwade
- Re: backtick and system return different exit codes
- From: Tim Hammerquist
- Re: backtick and system return different exit codes
- From: meenal_binwade
- Re: backtick and system return different exit codes
- From: Tim Hammerquist
- backtick and system return different exit codes
- Prev by Date: Re: Very serios perl problem? (BUG?)
- Next by Date: Getopt::Std , option with no argument
- Previous by thread: Re: backtick and system return different exit codes
- Next by thread: FAQ 5.30 How can I tell whether there's a character waiting on a filehandle?
- Index(es):
Relevant Pages
|