|Pathologically Eclectic Rubbish Lister|
Re: How to pass arguments in perl in linux system through system commandby vinoth.ree (Monsignor)
|on Mar 14, 2014 at 07:26 UTC||Need Help??|
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");
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