【发布时间】:2016-12-10 06:10:46
【问题描述】:
继我的previous question 涉及到另一个问题之后,我想我会根据这个问题来构建框架。
注意:subprocess.Popen()、communicate()、wait()的所有版本我都试过了,比如:
vowpal = subprocess.Popen('../../vowpal.sh',shell=True, stdout=subprocess.PIPE)
vowpal.communicate()
print vowpal.returncode
我有这样的文件结构:
├── src
│ ├── main
│ │ ├── costSensitiveClassifier.py
└── vowpal.sh
|
├── data
│ ├── output
│ │ ├── cost
| | |_______openCostClassifier.dat
| | |
在costSensitiveClassifier.py 中,我实际上是在尝试运行一个名为vowpal.sh 的脚本,该脚本对openCostClassifer.dat 进行一些操作,并将一些文件输出到与该文件相同的文件夹中。
costSensitiveClassifier.py 中的代码是:
import subprocess
print "Starting cost sensitive predictions using batch script\n"
subprocess.call("../../vowpal.sh")
print "Ending predictions"
vowpal.sh 中的代码是:
# !/bin/bash
vw --csoaa 24 data/output/cost/openCostClassifier.dat -f data/output/cost/csoaa.model
vw -t -i data/output/cost/csoaa.model data/output/cost/openCostClassifier.dat -p data/output/cost/csoaa.predict
问题始终是 bash 脚本的第二行需要首先输出一个名为 csoaa.model 的内容(请参阅 bash 脚本的第 1 行),一旦完成,第二行应该运行使用它文件输出csoaa.predict。但是,情况并非如此,我在运行 python 文件时得到了与 bash 脚本相关的错误代码:
vw (./io_buf.h:123): can't open: data/output/cost/csoaa.modelerrno = No such file or directory
我找到了this link,但不确定它是否是我需要的(我是否应该将睡眠调整为 bash 脚本完成并创建我需要处理的文件的预期时间?)。
【问题讨论】:
标签: python linux bash shell subprocess