Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在perl脚本中运行系统命令,该脚本包含@&引用;性格_Perl - Fatal编程技术网

在perl脚本中运行系统命令,该脚本包含@&引用;性格

在perl脚本中运行系统命令,该脚本包含@&引用;性格,perl,Perl,我有这样一个系统命令: unix_command "@output_file path_to_file" 现在,当我在perl脚本中尝试执行exec或system命令时,会出现以下错误: 需要运算符时获取字符串 你能帮我用Perl怎么做吗 谢谢你的帮助 非常感谢! Rakesh如果不需要插值,请使用单引号 system 'echo @a'; 如果是,请使用反斜杠 system "echo \@a"; 如果不需要插值,请使用单引号 system 'echo @a'; 如果是,请使用反斜杠

我有这样一个系统命令:

unix_command "@output_file path_to_file" 
现在,当我在perl脚本中尝试执行
exec
system
命令时,会出现以下错误:

需要运算符时获取字符串

你能帮我用Perl怎么做吗

谢谢你的帮助

非常感谢!
Rakesh

如果不需要插值,请使用单引号

system 'echo @a';
如果是,请使用反斜杠

system "echo \@a";

如果不需要插值,请使用单引号

system 'echo @a';
如果是,请使用反斜杠

system "echo \@a";

系统
实际上是两种不同的功能

你可以用它来启动一个程序。 以下语法用于启动程序:

system($prog, @one_or_more_args)
system({ $prog }, $arg0, @args)
使用其中一种语法,所有作为参数传递的字符串都会原封不动地传递给子程序

用法示例:

system('perl', '-e', 'my @a = "foo"; print "@a\n";');
use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('perl', '-e', 'my @a = "foo"; print "@a\n";');
system($cmd);
您可以使用它来执行shell命令。 以下语法用于执行shell命令:

system($shell_cmd)
以上简称

system('/bin/sh', '-c', $shell_cmd)
必须提供有效的shell命令。如果您正在构建命令,则需要注意正确地逃逸任何需要逃逸的内容

用法示例:

system('perl', '-e', 'my @a = "foo"; print "@a\n";');
use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('perl', '-e', 'my @a = "foo"; print "@a\n";');
system($cmd);

更具体地说,是shell命令

program @file1 file2
可按如下方式执行:

system('program', '@'.$file1, $file2);
如果您确实需要构造shell命令(例如,因为您想重定向输出),可以使用以下命令:

use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('program', '@'.$file1, $file2) . ' >output.txt 2>&1';
system($cmd);

系统
实际上是两种不同的功能

你可以用它来启动一个程序。 以下语法用于启动程序:

system($prog, @one_or_more_args)
system({ $prog }, $arg0, @args)
使用其中一种语法,所有作为参数传递的字符串都会原封不动地传递给子程序

用法示例:

system('perl', '-e', 'my @a = "foo"; print "@a\n";');
use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('perl', '-e', 'my @a = "foo"; print "@a\n";');
system($cmd);
您可以使用它来执行shell命令。 以下语法用于执行shell命令:

system($shell_cmd)
以上简称

system('/bin/sh', '-c', $shell_cmd)
必须提供有效的shell命令。如果您正在构建命令,则需要注意正确地逃逸任何需要逃逸的内容

用法示例:

system('perl', '-e', 'my @a = "foo"; print "@a\n";');
use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('perl', '-e', 'my @a = "foo"; print "@a\n";');
system($cmd);

更具体地说,是shell命令

program @file1 file2
可按如下方式执行:

system('program', '@'.$file1, $file2);
如果您确实需要构造shell命令(例如,因为您想重定向输出),可以使用以下命令:

use String::ShellQuote qw( shell_quote );

my $cmd = shell_quote('program', '@'.$file1, $file2) . ' >output.txt 2>&1';
system($cmd);

只需用反斜杠将
@
转义即可。例如:
系统“echo\@this”
unix\u命令“@output\u file path\u to\u file”
在我看来不合适。您确定它不是
unix\u命令“@output\u file”“path\u to\u file”
?我想你在我的回答中指的是后者。你可以简单地用反斜杠避开
@
。例如:
系统“echo\@this”
unix\u命令“@output\u file path\u to\u file”
在我看来不合适。您确定它不是
unix\u命令“@output\u file”“path\u to\u file”
?我想你在我的回答中是指后者。