您在后面的代码段中有注射错误。因此,我的意思是,当你建立你的shell命令时,你忘了将$file
的值转换成一个产生值$file
的shell文字。这真是一口,所以我会在下面说明这意味着什么。
说$file
包含a b.txt
。
my @cmd = ("samtools", "sort", $file, "01_sorted.SNP");
system(@cmd);
相当于
system("samtools", "sort", "a b.txt", "01_sorted.SNP");
此执行samtools
,并通过了三根弦sort
,a b.txt
和01_sorted.SNP
把它作为参数。
my $cmd = "samtools sort $file 01_sorted.SNP";
system($cmd);
相当于
system("samtools sort a b.txt 01_sorted.SNP");
此执行壳,传递字符串作为要执行的命令。
反过来,外壳将执行samtools
,经过串sort
,a
,b.txt
和01_sorted.SNP
把它作为参数。
samtools
无法找到文件a
,所以它给出了一个错误。
如果您需要构建shell命令,请使用String::ShellQuote
。
use String::ShellQuote qw(shell_quote);
my $cmd = shell_quote("samtools", "sort", "a b.txt", "01_sorted.SNP");
system($cmd);
相当于
system("samtools sort 'a b.txt' 01_sorted.SNP");
此执行壳,传递字符串作为要执行的命令。
接着,shell将执行samtools
,将三个字符串sort
,a b.txt
和01_sorted.SNP
作为参数传递给它。
显示'$ file'的内容。 – toolic 2014-10-28 17:34:48