We help IT Professionals succeed at work.

PERL script to instanciate windows executable

Alexandre Takacs
Alexandre Takacs used Ask the Experts™
on
Hello

I will need so help to create a small Perl script that will get as a parameter a command to execute in a windows shell.

My requirement is that the script should accept two input parameters, the first being the command to execute and the second the parameters to said command.

In other words something like myscript.pl "dir" "*.*" which will in turn do an exec() with the command "dir *.*".

No need to check return value or even command validity.

I guess it's fairly trivial but I'm completely perl un-litterate...

Thanks in advance for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
In its very simplest form your can do the below

$first = shift; #Get first argument from script parameters
$second = shift; #Get first argument from the script parameters
`$first "$second"`; #Run the commend


If it was the very first line in your script you could just do the below which will use the script arguments directly

`$_[0] "$_[1]"`;

Note that these are backticks ` not an apostrophe '. The double quotes are optional but will allow you to pass arguments with a space in doublequotes to your script and have it passed on.


If you have multiple arguments to your script you'll need to join them together first

$first = shift; #Get the command to run from the script arguments
$args = join (' ',@_); #Join the script paremeters @_ together with a space between into a single variable
`$first $args`; #Execute the command

Author

Commented:
Hello

thanks - that did the trick

Sorry for delayed response