python中的子进程错误

python中的子进程错误,python,operating-system,subprocess,system-calls,Python,Operating System,Subprocess,System Calls,我正在使用PDFminer将pdf转换为html文件 错误代码: def pdf2html(filename, path): outfile_name = filename.split('.')[0] + '.html' cmd = ['pdf2txt.py', '-o', path + outfile_name, path + filename] print ' '.join(cmd) subprocess.call(cmd, shell=True) file

我正在使用PDFminer将pdf转换为html文件

错误代码:

def pdf2html(filename, path):
    outfile_name = filename.split('.')[0] + '.html'
    cmd = ['pdf2txt.py', '-o', path + outfile_name, path + filename]
    print ' '.join(cmd)
    subprocess.call(cmd, shell=True)

filename = "040214_MOOCs.pdf"
path = "/Users/andy/GoogleDrive/Debate/intelligencesquaredus/data/"
pdf2html(filename, path)
上面的代码应该运行“pdf2txt.py-o/Users/andy/GoogleDrive/discussion/intelligencesquaredus/data/040214_MOOCs.html/Users/andy/GoogleDrive/discussion/intelligencesquaredus/data/040214_MOOCs.pdf” 在壳里

但是没有使用上述代码的输出(040214_MOOCs.html)。如果我在shell中运行该命令,它将毫无问题地生成输出

然后我尝试了下面的脚本,它工作了,唯一的区别是使用os.system而不是subprocess.call:

def pdf2html(filename, path):
    outfile_name = filename.split('.')[0] + '.html'
    cmd = ['pdf2txt.py', '-o', path + outfile_name, path + filename]
    print ' '.join(cmd)
    os.system(' '.join(cmd))

filename = "040214_MOOCs.pdf"
path = "/Users/andy/GoogleDrive/Debate/intelligencesquaredus/data/"
pdf2html(filename, path)
另外,在错误的代码中,如果我设置shell=False,代码也会工作,为什么会这样? 在这种情况下,当os.system工作时,为什么子流程不工作?
非常混乱,需要解释

这可能是因为外壳不匹配。您是否可以尝试在没有
shell=True
的情况下运行子流程调用

如果shell=True,则调用的shell可能与当前使用的shell不同。因此,它将不具有相同的路径等。