【问题标题】:Called subprocess doesn't execute bash script in sequence被调用的子进程不按顺序执行bash脚本
【发布时间】: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 脚本完成并创建我需要处理的文件的预期时间?)。

【问题讨论】:

  • 您似乎需要一个工作流管理库,例如snakemakeruffus
  • 另外,您的错误表明您的脚本正在寻找 csoaa.modelerrno 而不是 csoaa.model

标签: python linux bash shell subprocess


【解决方案1】:

这是 vowpal 中的一个问题。它试图创建一个错误文件,但它不能。原因之一可能是目录“data/output/cost/”不存在。

这就是对我造成同样错误的原因。

【讨论】:

    猜你喜欢
    • 2015-07-04
    • 1970-01-01
    • 2017-02-12
    • 2022-08-19
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    相关资源
    最近更新 更多