Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Problem in perl script for checking exit status of shell script

by sarf13 (Beadle)
on Feb 08, 2012 at 08:52 UTC ( [id://952437]=perlquestion: print w/replies, xml ) Need Help??

sarf13 has asked for the wisdom of the Perl Monks concerning the following question:

package TestEngine::Testcase::Logic::Cmd; use Test::More; use base qw(Test::Cmd); sub new { my ($self,$cmd) = @_; my $self = { cmd => $cmd, type => "", workdir => '/tmp/', }; bless $self; return $self; } sub isSuccess { my ($self) = @_; my ($interpreter, $args); if ($^O == 'linux') { $interpreter = '/usr/bin/ksh'; $args = qq(-c "$self->{cmd}"); } elsif ($^O == 'MSWin32') { # TODO: KNOWN ISSUE # This interpret does not provide correct execute status $interpreter = 'c:\windows\system32\command.com'; $args = "/c $self->{cmd}"; } else { die "unsupported platform '$^O'"; } # // todo: ensure run() return 0 for success, otherThan0 for failu +re #print qq($self->run(prog =>$interpreter, args =>$args )); return ok($self->run(prog =>$interpreter, args =>$args ) == 0, $se +lf->{desc} ); #print "$self->{desc}\n"; } sub setDescription { my ($self, $string) = @_; $self->{desc} = $string; } 1;

I am using above perl script package for checking the exit value from shell script which I had mentioned bellow. If shell script exit with “0 exit status” perl script will check in its “isSuccess” subroutine and pass OK. When I am checking exit status of shell script its giving 0 exit status. But in perl script it’s giving me NOT OK value. I am not able to figure it out where exactly the problem.

tag=0 for file in $Rejected_File_Path/* #for file in /home/oracle/sarfaraz/scotia/QA_RELEASE_20120123/release/ +log/Rejected/* do # echo "$file" file_name=`grep "#RD#" $file|cut -d"," -f8` #echo "=====>>>$file_name" #READING DATA FROM SQL OUTPUT FILE# while read line do file_name_match=`grep "$file_name" $line` #echo "------->>>$file_name_match----" if [ "$file_name_match" == "$file_name" ] then rej_code=`grep ",2001," $file` #echo "===$rej_code" if [ "$rej_code" != "" ] then echo "FOUND REJECTION CODE" tag=127 fi else echo "THRER IS NO ERROR CODE IN REJECTION FILE ...." fi done < tempimp1 done #echo "==$tag" rm -f tempimp1 #vel=`$?` echo "===$val" if [ "$tag" == "127" ] then echo "FINAL SUCCESS ...." # echo "===$val" echo $? exit $val else echo "FAILED ...." exit 127 fi

Thanks for your kind support

little update to narrow down my shell script problem when i run this program from perl script

1.when i am giving all mandatory paths on shell script itself (hardcoding the path) its exit with value 0 (zero) 2.when the same script use to read all mandatory path from external file then its exit with value "32512"

Is this problem to read external file which affect the exit status or another issue.

please suggest any approach

Replies are listed 'Best First'.
Re: Problem in perl script for checking exit status of shell script
by Ratazong (Monsignor) on Feb 08, 2012 at 09:08 UTC

      Thanks for your reply

      its returning 127 inteed of 0, i am trying to narrow down the probelem. well in my shell script i read an external file for reading PATH for required files. while i am reading this external file then the perl script giving the NOT OK satement. another hand if i just hardcoded all the path on shell script itself then perl script giving me OK statement.

      i am just checking its a problem reading external file or someting else.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://952437]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found