0

我试图在 perl 中执行这个命令,它在 bash 中运行良好。但是从 perl 执行时,它不起作用。也许我没有逃脱正确的角色?能否请你帮忙。

my $comp_command = "./jnx_comp.py <(/usr/bin/ssh $boss\@$ftpServer[$j] '/bin/cat $compList[0]') <(/usr/bin/ssh $boss\@$ftpServer[$j] '/bin/cat $compList[1]')"

my $result = `$comp_command`;

这是运行脚本时给我的错误:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `./jnx_comp.py <(/usr/bin/ssh jnxapps@dcsftp01n '/bin/cat /home/A11256/out/recon/JNX_EOD_20130606.csv'
4

1 回答 1

5

使用时它运行良好,bash因为它是一个有效的bash命令。

使用Perl 执行时它不起作用,sh因为它不是有效的sh命令。

如果要执行bash命令,则需要实际执行bash.

my $result = `bash -c bash_commmand_here`;

让我们解决一些插值问题。

use String::ShellQuote qw( shell_quote );

my $remote_cmd1 = shell_quote('/bin/cat', $compList[0]);
my $remote_cmd2 = shell_quote('/bin/cat', $compList[1]);

my $ssh_cmd1 = shell_quote('/usr/bin/ssh', "$boss\@$ftpServer[$j]", $remote_cmd1);
my $ssh_cmd2 = shell_quote('/usr/bin/ssh', "$boss\@$ftpServer[$j]", $remote_cmd2);

my $bash_cmd = "./jnx_comp <( $ssh_cmd1 ) <( $ssh_cmd2 )";

my $sh_cmd = shell_quote('bash', '-c', $bash_cmd);

`$sh_cmd`
于 2013-06-09T01:59:04.893 回答