【发布时间】:2018-08-17 10:35:29
【问题描述】:
我正在尝试从 python 代码执行 bash 脚本。 bash 脚本在 for 循环内的管道中有一些 grep 命令。当我运行 bash 脚本本身时,它没有给出任何错误,但是当我在 python 代码中使用它时,它说:grep:write 错误。
我在python中调用的命令是:
subprocess.call("./change_names.sh",shell=True)
bash 脚本是:
#!/usr/bin/env bash
for file in *.bam;do new_file=`samtools view -h $file | grep -P '\tSM:' | head -n 1 | sed 's/.\+SM:\(.\+\)/\1/' | sed 's/\t.\+//'`;rename s/$file/$new_file.bam/ $file;done
我错过了什么?
【问题讨论】:
-
如果你也发布你的 bash 脚本可能会有所帮助
-
更新了帖子。
-
尝试改用
subprocess.Popen()。 -
我通常使用
subprocess.check_output("bash script.sh", shell=True)没有任何问题 -
如果你避免使用 bash 并使用 pysam 来获取操作,它可能会更容易和更干净。