Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

by vinoth.ree (Monsignor)
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.

 system("command", "arg1", "arg2", "arg3");

You can call your second perl script with arguemnt as,

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

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

system("Path of/","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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078297]
NodeReaper reads the Necronomicon

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-11-20 01:31 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (282 votes). Check out past polls.