Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Run Linux Command from Perl Script

by ant (Scribe)
on Mar 23, 2007 at 13:58 UTC ( #606239=perlquestion: print w/replies, xml ) Need Help??

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


I have a perl script running on Linux environment.

I have a list of Oracle form files. These files need to be translated into text files, which I can open and look for various patterns etc.

I loop though the perl script and create a shell script which looks like this
/oracle/IAS/bin/ module=/home/forms/src/ealib450.pll module_type=library userid=XXXX/XXXX@XXXX compile_all=yes batch=yes script=yes Output_File=ealib450.txt debug=yes

I then try to execute this command via, system command as I want the script to continue running afterwards (so exec is out).

Code for running the command is system("sh $temp_shell2")|| print "2 failed to execute $!\n";

I read this here, but still no luck!

This fails with a 'Inappropriate ioctl for device' message, which I read could be a red herring!

However if I open the Linux window, go to the directory and type the filename in, the script executes!

Just to make matters more confusing, I can create a shell script in my windows environment with exactly the same command, putty the file over to the Linux box and Plink the file, and the file executes!

Why can I not execute the Linux script Via the Perlscipt that created it in the Linux environment?

Thanks in Advance


Replies are listed 'Best First'.
Re: Run Linux Command from Perl Script
by kyle (Abbot) on Mar 23, 2007 at 14:08 UTC

    Have a look at the documentation for system. Unlike virtually everything else, it returns non-zero for failure, so where you say "system || print "error"", you need to have something more like:

    system( "sh $temp_shell2" ) == 0 or die "2 failed to execute: $!";

    I think right now it's telling you that it fails when it's not.

Re: Run Linux Command from Perl Script
by jettero (Monsignor) on Mar 23, 2007 at 14:11 UTC

    ... if it's a regular old perl program then the problem probably has to do with some kind of interpolation ambiguity. See the multi-arg usage of system and it might just solve the problem (eg, system "sh", $script_name, @other_arguments). You shouldn't need to call "sh," but it certainly doesn't hurt anything either.

    UPDATE: I deleted some of this post because kyle is correct and I missed that return value reversal completely.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2023-09-30 22:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found