我正在从perl为ContentCheck.pl进行系统调用,并传递带目录(具有空格)的参数。所以我通过他们的报价,但他们没有被拾起在ContentCheck.pl文件将参数传递给带有空格的目录的命令行
Random.pm 1)
my $call = "$perlExe $contentcheck -t $target_path -b $base_path -o $output_path -s $size_threshold";
print "\ncall: ".$call."\n";
system($call);
Contentcheck.pl
use vars qw($opt_t $opt_b $opt_o $opt_n $opt_s $opt_h); # initialize
getopts('t:b:o:n:s:h') or do{
print "*** Error: Invalid command line option. Use option -h for help.\a\n";
exit 1};
if ($opt_h) {print $UsagePage; exit; }
my $tar;
if ($opt_t) {$tar=$opt_t; print "\ntarget ".$tar."\n";} else {
print " in target";
print
"*** Error: Invalid command line option. Use option -h for help.\a\n";
exit 1;}
my $base;
if ($opt_b) {$base=$opt_b;} else {
print "\nin base\n";
print "*** Error: Invalid command line option. Use option -h for help.\a\n";
exit 1;}
这是输出在命令行中
call: D:\tools\PacketCreationTool/bin/perl/winx64/bin/perl.exe D:/tools/PacketCr
eationTool/scripts/ContentCheck.pl -t "C:/Documents and Settings/pkkonath/Deskto
p/saved/myMockName.TGZ" -b "input file/myMockName.TGZ" -o myMockName.validate -s
10
target C:/Documents
in base
*** Error: Invalid command line option. Use option -h for help.
欢迎任何建议! 谢谢。
2)当我通过这种方式
my $call = "$perlExe $contentcheck -t \"$target_path\" -b \"$base_path\" -o $output_path -s $size_threshold";
print "\ncall: ".$call."\n";
system($call);
这是输出
call: D:\tools\PacketCreationTool/bin/perl/winx64/bin/perl.exe D:/tools/PacketCr
eationTool/scripts/ContentCheck.pl -t ""C:/Documents and Settings/pkkonath/Deskt
op/saved/myMockName.TGZ"" -b ""input file/myMockName.TGZ"" -o myMockName.validat
e -s 10
target C:/Documents
in base
*** Error: Invalid command line option. Use option -h for help.
3)
my $call = "$perlExe, $contentcheck, '-t', $target_path, '-b', $base_path, '-o', $output_path, '-s', $size_threshold";
print "\ncall: ".$call."\n";
system($call);
这是输出:
Can't open perl script ",": No such file or directory
无法打开Perl脚本“”:没有这样的文件或目录;这是我现在得到的错误。 – superstar 2010-04-09 15:40:45
@superstar你复制并粘贴了friedo的代码,或者你有类似'system(“$ perlExe,$ contentcheck,...”)''的东西吗? – 2010-04-09 15:51:18
@gbacon:我在问题中使用了不同的选项,如1)2)3) – superstar 2010-04-09 19:07:11