我正在从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);
Run Code Online (Sandbox Code Playgroud)
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;}
Run Code Online (Sandbox Code Playgroud)
这是命令行中的输出
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.
Run Code Online (Sandbox Code Playgroud)
欢迎任何建议!谢谢.
2)当我以这种方式通过时
my $call = "$perlExe $contentcheck -t \"$target_path\" -b \"$base_path\" -o $output_path -s $size_threshold";
print "\ncall: ".$call."\n";
system($call);
Run Code Online (Sandbox Code Playgroud)
这是输出
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.
Run Code Online (Sandbox Code Playgroud)
3)
my $call = "$perlExe, $contentcheck, '-t', $target_path, '-b', $base_path, '-o', $output_path, '-s', $size_threshold";
print "\ncall: ".$call."\n";
system($call);
Run Code Online (Sandbox Code Playgroud)
这是输出:
Can't open perl script ",": No such file or directory
Run Code Online (Sandbox Code Playgroud)
请改用多参数形式system.这将使您免于处理shell转义问题,因此更加安全.
system( $perlExe, $contentcheck, '-t', $target_path, '-b', $base_path, '-o', $output_path, '-s', $size_threshold );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4272 次 |
| 最近记录: |