Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

executing system command from within perl script

by manishrathi (Beadle)
on Dec 08, 2010 at 16:13 UTC ( [id://876059]=perlquestion: print w/replies, xml ) Need Help??

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

I want to execute a command line command from within perl script.

By that I mean, if I want to execute "perl insideScript.pl" from within"perl outsideScript.pl". How can I do this ?

Do I just add a line of code "perl insideScript.pl" in the "perl outsideScript.pl", wherever I want to run insideScript or do I need to do anything else ?

Thanks
  • Comment on executing system command from within perl script

Replies are listed 'Best First'.
Re: executing system command from within perl script
by Ratazong (Monsignor) on Dec 08, 2010 at 16:31 UTC

    Use the system-command for this, e.g. my $result = system("perl insideScript.pl");.

    Alternatively, you could use backticks (`` or qx//) (e.g. my @result = `perl insideScript.pl`;).

    As you see, the difference is on how to handle the output and result of your inner script.

    HTH, Rata
Re: executing system command from within perl script
by cdarke (Prior) on Dec 08, 2010 at 16:52 UTC
    I suspect you are attempting to use perl as if it was a shell. UNIX shells inspect commands and decide if they are keywords, aliases, built-ins, functions or external programs (or other exotics). This is quite unusual for a programming language, but convienient for a command-line driven shell. Perl, like most programming languages, does not work in this way.

    See system, which is based upon the function of the same name in C (although it is smarter). You can also use back-ticks `` as you would in a shell, or qx.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found