my $output=qq{sudo /usr/bin/python /home/processLog.py \Q$name\E \Q$ag
+e\E \Q$text\E \Q$id\E};
return `$output`;
It works using interpolating quote-like operator qq{} and escaping operators \Q...\E, both described in Quote and Quote like Operators.
Another approach might be using open or modules like IPC::Run or IPC::Cmd to run a command with a list (not a string) of arguments:
open my $fh, "-|", qw{sudo /usr/bin/python /home/processLog.py}, $name
+, $age, $text, $id or die $!;
return do {local $/; <$fh>};
use IPC::Run;
run [qw{sudo /usr/bin/python /home/processLog.py}, $name, $age, $text,
+ $id], ">", \(my $return) or die "run: $?";
return $return;
Warning: all code in this message is untested.
Update: using quotemeta for quoting shell commands is a hack, you should run a list of arguments instead, or use at least some shell-related module like String::ShellQuote.
Update 2: the code I suggested will discard any newlines in the interpolated variables instead of escaping them properly, so I stroke it out. Thanks ambrus for correcting me.
Edit: removed quotes from \Q...\E approach as they are entirely unnecessary in this case. |