Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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]
[atcroft]: Discipulus: I looked back at your note about my Padre question from a while back, and it made me look again... as a result, I found what I was missing and was able to make the change. Thank you!

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-02-24 20:31 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (311 votes). Check out past polls.