Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to pass arguments in perl in linux system through system command

by vinoth.ree (Parson)
on Mar 14, 2014 at 07:26 UTC ( #1078297=note: print w/ replies, xml ) Need Help??


in reply to How to pass arguments in perl in linux system through system command

Hi sumandas,

system() accepts as argument either a scalar or an array. If the argument is a scalar, system() uses a shell to execute the command. If the argument is an array it executes the command directly, considering the first element of the array as the command name and the remaining array elements as arguments to the command to be executed.

Its highly recommended for efficiency and safety reasons that you use an array to pass arguments to system call.

Ex:
 system("command", "arg1", "arg2", "arg3");
So,

You can call your second perl script script2.pl with arguemnt as,

system("path of your perl interpreter/perl","Path of/script2.pl","Path of /$configfile");

If you have given the execution permission and your second script script2.pl has the shabang line ("#!/usr/bin/perl"), so u can simply execute your script as below,

system("Path of/script2.pl","Path of /$configfile");

The return value is set in $?. This value is the exit status of the command as returned by the 'wait' call, to get the real exit status of the command you have to shift right by 8 the value of $? ($? >> 8).

If the value of $? is -1, then the command failed to execute, in that case you may check the value of $! for the reason of the failure.


All is well


Comment on Re: How to pass arguments in perl in linux system through system command
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-12-18 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls