【发布时间】:2018-10-30 15:43:11
【问题描述】:
我想通过python执行这个shell命令,我试过用
shell="ls *R1.fastq.gz|while read a; do b=${a%R1.fastq.gz}R2.fastq.gz; c=${a%R1.fastq.gz}R1.out.fq; d=${a%R1.fastq.gz}R2.out.fq; e=${a%R1.fastq.gz}.s.fq; echo "sickle pe -t sanger -f $a -r $b -o $c -p $d -s $e"; done >SICKLE.sh"
system.os(shell)
但是得到一个SythaxError: InvalidSyntax 我做了一些研究,也许我应该使用subprocces ?但我对此很陌生,我们能帮帮我吗?
【问题讨论】:
-
另外你必须在你的命令中转义引号,或者使用单引号来包含你的字符串。
-
@chrisz 转义引号是什么意思?搭上他们?但如果没有它们,它将无法正常工作
-
一种方式是这样的:shell="ls *R1.fastq.gz|while read a; do b=${a%R1.fastq.gz}R2.fastq.gz; c= ${a%R1.fastq.gz}R1.out.fq;d=${a%R1.fastq.gz}R2.out.fq;e=${a%R1.fastq.gz}.s.fq ; echo \"sickle pe -t sanger -f $a -r $b -o $c -p $d -s $e\"; 完成 >SICKLE.sh"
标签: python-3.x shell command subprocess os.system