Perl array extension in command line arguments

I want to call a shell command from a Perl script. Command arguments are present in the Perl array.

What is the easiest way to do this?

thanks for answers

+3
source share
2 answers

You probably need to call system, and most effectively pass the parameters in a list, which avoids using the shell to parse the command line. Call type

my $status = system 'command', @arguments;

should do what you need.

+4
source

Typically, two forms are usually used to run programs:

  • takes a path and argument list
  • accepts a shell command.

The first is safer and requires less resources.

system($prog, @args);             # @args > 0
system({ $prog } $prog, @args);   # @args >= 0

, String:: ShellQuote ( unix) Win32:: ShellQuote ( Win32), .

use String::ShellQuote qw( shell_quote );
my $shell_cmd = shell_quote($prog, @args);
system($shell_cmd);
+1

All Articles