python subprocess命令行解析错误 [英] python subprocess Command Line Parsing Error

查看:355
本文介绍了python subprocess命令行解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个用子进程WolfPsort程序编码的python程序. 它是用于蛋白质定位检测程序的生物信息学工具. 但是,python子进程不会执行我的输入文件. 这是代码

I am running a python program I have coded with a subprocess WolfPsort Program. It is a bioinformatics tool for protein localization detection program. However, the python subprocess does not excute my input file. This is the code

#!/usr/bin/python
# secref.py is for secretome refining

import os
import sys
import subprocess

if len(sys.argv) != 2:
        print >> sys.stderr, 'Usage: python secref.py [*.fasta]'
        exit(1)

if sys.argv[1].endswith('.fasta'):
        filename = sys.argv[1]
else:
        print >> sys.stderr, 'Input correct file... [*.fasta]'
        exit(1)

filehandle = open(filename,'r')

progWolf = subprocess.Popen(['runWolfPsortSummary','fungi','<',filename,'>','tmpWolfResult'])
progWolf.wait()

如果我运行代码,它将给出如下错误消息:

If I run the code it gives error message like this:

[karyo@hostname secref.1.0]$ python secref.py A.carbonarius.fasta 

Command Line Parsing Error; Do not know what to do with argument "<"

Usage:
    runWolfPsortSummary [*OPTIONS*] *organismType*

    runWolfPsortSummary (--usage|--help|--man)

    Pipe sequences in from standard in.

子过程无法识别<";符号,但WolfPsort程序需要<"才能识别输入的fasta文件,并且需要>"来写入临时结果文件.

The subprocess dose not recognise "<" symbol, but WolfPsort Program needs "<" to recognise the input fasta file and ">" is required to write a temporary result file.

如何使子进程理解参数<"?

How can I make the subprocess to understand the argument "<"?

请帮帮我!

推荐答案

我猜您正在尝试使用Shell Magic从文件名读取并写入tmpWolfResult.为了实现这一目标,您需要:

I'm guessing you're trying to use shell magic to read from filename and write to tmpWolfResult. In order to make that happen, you need:

progWolf = subprocess.Popen('runWolfPsortSummary fungi < %s > tmpWolfResult'%filename, shell=True)

我不得不提到,由于此输入来自命令行参数,因此从技术上讲不是安全/受信任的,并且有权在您的系统上运行此脚本的恶意用户可能会做一些令人讨厌的事情

I feel obligated to mention that since this input is coming from a commandline argument, it's technically not safe/trusted and a malicious user with access to run this script on your system could do some nasty things.

但是,很可能您正在分发此脚本(或仅自己使用它),并且您和您的用户可能对构建自己的系统不感兴趣...

However, it's probably more likely that you're distributing this script (or just using it yourself) and you and your users probably aren't interested in messing up your own system...

这篇关于python subprocess命令行解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆