引发child_exception的原因OSError:[Errno 2]没有这样的文件或目录

时间:2016-04-14 11:32:07

标签: python subprocess

我的代码:

jarfile = "res/StringUtilsv102.jar"
#project = "5.1"
#apkName = "com.am.fl"  // added to show what ll b strin passed on to the function
def generate_idfile(project,apkName):
    cmd = "java -jar %s listStringIds  %s %s" %(jarfile, project ,apkName)
    arglist = shlex.split(cmd)
    outfile = 'output.txt'
    idfile = "idfile.txt"
    if(os.path.exists(idfile)):
        os.remove(idfile)
    process = subprocess.Popen(arglist, cwd=os.getcwdu())
    process.wait()
    os.rename(outfile, idfile)

O / p抛出错误,因为没有这样的文件或目录。 我已经尝试了所有可能的解决方案来清除错误但无助。

Error:
Traceback (most recent call last):

  File "/home/local/libraries/i18n/data_set/data_set.py", line 150, in init_logical_path
    genStringIdXml.generate_idfile(project, apkName)
  File "/home/local/ANT /i18n/data_set/genStringIdXml.py", line 27, in generate_idfile
    process = subprocess.Popen(arglist, cwd=os.getcwdu())
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

1 个答案:

答案 0 :(得分:0)

您需要启动java二进制存在的进程:

process = subprocess.Popen(arglist, cwd="/path/to/java/dir")

或使用shell=True允许PATH环境变量为您解析路径。

process = subprocess.Popen(arglist, shell=True)