您在後面的代碼段中有注射錯誤。因此,我的意思是,當你建立你的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