exit status problem.

F

Fearban

Hi,

I am calling a perl script. This perl script will exit(9) when finished
processing.
I am calling this script from a borne shell script. I need to catch the
return value.
The following is a simple example.
But i can not catch the "9"

perltest.pl
#!/opt/bin/perl
print("hello\n");
exit 9;

here is the shell script

#!/bin/ksh
var=`perl perltest.pl`
print ${var}

Also how is this done if perl is the calling script.

#!/opt/bin/perl
my $var = 8;
print("$var\n");
$var= system(perl perltest.pl);
print ($var);



Can any one help.?
 
J

Jürgen Exner

I need to catch
the return value. [...]
$var= system(perl perltest.pl);
print ($var);

Did you read the documentation for the functions that you are using?
From 'perldoc -f system':
The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value divide by 256.

jue
 
J

Jürgen Exner

I am not getting any value returned ..

What do you mean? Please quote appropriate context -as has been a proven
custom for over 2 decades- such that your readers have a chance to know what
you are talking about.

jue
 
F

Fearban

var=`perl perltest.pl`
print ${var}

Nothing is being returned at this point ..

So division will not help me get the result
 
I

it_says_BALLS_on_your forehead

Hi,

I am calling a perl script. This perl script will exit(9) when finished
processing.
I am calling this script from a borne shell script. I need to catch the
return value.
The following is a simple example.
But i can not catch the "9"

perltest.pl
#!/opt/bin/perl
print("hello\n");
exit 9;

here is the shell script

#!/bin/ksh
var=`perl perltest.pl`
print ${var}

script: try.pl
--------------------
#!/usr/bin/perl

print "hi\n";
exit 9;


script: execute_perl
-----------------------------
#!/usr/bin/ksh
$@
echo $?

....
execute_perl try.pl
hi
9
 
X

xhoster

Hi,

I am calling a perl script. This perl script will exit(9) when finished
processing.
I am calling this script from a borne shell script. I need to catch the
return value.
The following is a simple example.
But i can not catch the "9"

perltest.pl
#!/opt/bin/perl
print("hello\n");
exit 9;

here is the shell script

#!/bin/ksh
var=`perl perltest.pl`
print ${var}

`` in the shell, like in perl, captures the *output*, not the exit status.
You probably need to look in $?, but I don't know--this isn't a bash group,
afterall.
Also how is this done if perl is the calling script.

#!/opt/bin/perl
my $var = 8;
print("$var\n");
$var= system(perl perltest.pl);
print ($var);

Can any one help.?

Have you read the documentation on the function you are using?

Xho
 
T

Tad McClellan

I am calling a perl script.


If you were calling a python script, or another shell script, or
a binary originally written in C or in Java, then you would capture
the exit status in the shell the same way.

How to capture the exit status is not related to the programming
language of the executable, it is related to the shell that you are using.

You do not have a Perl question. (so you are looking for an answer
in the wrong place.)

Also how is this done if perl is the calling script.


Now that *is* a Perl question...

$var= system(perl perltest.pl);


And the docs for the function that you are using tell you how
that is done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,332
Latest member
LeesaButts

Latest Threads

Top