你在后面的 sn-p 中有注入错误。我的意思是,当你构建你的 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");
这会执行shell,将字符串作为要执行的命令传递。
反过来,shell 将执行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,将字符串作为要执行的命令传递。
反过来,shell 将执行samtools,将三个字符串sort、a b.txt 和01_sorted.SNP 作为参数传递给它。