【发布时间】:2015-08-17 17:55:02
【问题描述】:
我有一组代码,我想通过 .py 文件而不是 .bat 文件按顺序运行,我该怎么做?我有以下代码:
#!/usr/bin/python
import sys
import os
bashCommand = "./available_itemsawk.sh"
os.system(bashCommand)
python_command="python run_process.py"
os.system(python_command)
我有两个问题: 1)我的shell脚本(available_itemsawk.sh)如下:
#!/bin/bash
join -1 4 -2 1 -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2 <(sort -k4 abc.txt) <(sort -k1 cdf.txt) > join.txt
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' join.txt > temp
mv temp join.txt
但是,当我通过 python 脚本调用并运行它时,出现以下错误:
sort: write failed: standard output: Broken pipe
sort: write error
2) 如何通过os.system进程串联运行脚本?
abc.txt
chr7 99999667 100000138 ENSG00000078487:I17.1 -
chr7 100000139 100000199 ENSG00000078487:E17.1 ENSE00001180416 -
chr9 100000046 100000367 ENSG00000203279:E2.1 ENSE00001678182 -
chr3 99998605 100000561 ENSG00000036054:I5.1 +
chr3 100000562 100000586 ENSG00000036054:E6.1 ENSE00001916783 +
chr3 100000586 100000691 ENSG00000036054:E6.2 ENSE00003639820|ENSE00001916783 +
chr9 99983518 100000704 ENSG00000159712:I1.1 -
chr9 100000368 100000704 ENSG00000203279:I1.1 -
chr9 100000731 100000765 ENSG00000254876:E1.1 ENSE00002183448 +
chr9 100000765 100000779 ENSG00000197816:E1.1 ENSE00003621967 +
cdf.txt
ENSG00000078487:I17.1
ENSG00000254876:E1.1
ENSG00000036054:E6.1
ENSG00000036054:I5.1
ENSG00000197816:E1.1
【问题讨论】:
-
看起来像是 shell 脚本本身的错误,与 python 无关。你能确认当你直接执行shell脚本时它可以工作吗?
-
@quantum_random: 独立运行很好,我也是用mac终端作为平台来运行代码的。
-
你能提供一个abc.txt和cdf.txt内容的样本吗?我可以尝试在我的最后重现这个。我正在使用 Ubuntu,但这没关系。
-
我把它放在了问题中。
-
我在我的电脑上试过了,一切运行良好。当然,我没有在上面的代码中运行 python_command。一种解释是“Broken pipe”错误来自 run_process.py 而不是 shell 脚本。尝试注释掉代码的最后两行,看看错误是否仍然发生。否则我就没主意了。