Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2016-10-25 21:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.