在Python 2.7中使用stdin,stdout和stderr的正确方法是什么?

问题描述 投票:0回答:1

有人在Python中使用subprocess.call命令有经验吗?每当我的代码中出现这样的行,我都会不断出错:

INFILE1 = open(script_dir+"/Scripts/plot_TSS_profile.R","r")
  subprocess.call("Rscript","--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stdin=INFILE1,  stderr=ERR_LOG,stdout=OUT_LOG,shell=True)
   INFILE1.close(). 

如果我按原样保留代码,则会由于某个原因,即使它们是代码中的唯一值,也会由于每个原因而为每个stdin,stderr和stdout找到多个值,从而导致错误。如果我删除这些参数,然后将infile放在“ --args”之后的方括号中,则似乎无法读取文件,因为它说“缓冲区应该是整数。”

例如,这种方式给出了缓冲区错误:

INFILE1 = script_dir+"/Scripts/plot_TSS_profile.R"
    subprocess.call("Rscript",INFILE1,"--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stderr=ERR_LOG,shell=True)
    INFILE1.close()

这是我的错误输出,以获取更多具体信息:

buffsize上的一个:

追踪(最近通话):文件“ /mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py”,第277行,位于>

    step5(ERR_LOG,OUT_LOG,args,proj_dir,script_dir,filenames)
  File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 165, in step5
    subprocess.call("Rscript",INFILE1,"--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stderr=ERR_LOG,shell=True)
  File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 343, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

以及存在多个值的另一个错误:

 Traceback (most recent call last):
  File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 272, in <module>
    step5(ERR_LOG,OUT_LOG,args,proj_dir,script_dir,filenames)
  File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 165, in step5
    subprocess.call("Rscript","--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stdin=INFILE1,stderr=ERR_LOG,stdout=OUT_LOG,shell=True)
  File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
TypeError: __init__() got multiple values for keyword argument 'stdin'

谢谢

有人在Python中使用subprocess.call命令有经验吗?每当我的代码中出现这样的行时,我都会不断收到错误消息:INFILE1 = open(script_dir +“ / Scripts / plot_TSS_profile.R”,“ r”)...

python python-2.7 subprocess popen
1个回答
0
投票

主要问题是call接受参数的[[list

© www.soinside.com 2019 - 2024. All rights reserved.