【问题标题】:execute shell code interactively in python在 python 中交互地执行 shell 代码
【发布时间】:2013-04-01 14:39:41
【问题描述】:

我从 python 调用 pdflatex 使用

executeCode = 'pdflatex -shell-escape "' + packageName + '.tex"'
result = os.system(executeCode)

LaTeX 文档可能有错误,在这种情况下 pdflatex 要求键盘输入。 对于 python,这与无限循环相同。在 PyScripter 中,我什至无法停止 python。我必须杀死 pdflatex。

现在我需要两件事 1.我想看pdflatex的输出 2.我需要在控制台上与pdflatex交互

我该怎么做?

【问题讨论】:

    标签: python console


    【解决方案1】:

    如果您使用--interaction nonstopmode 选项,pdflatex 将不会停止并要求输入。

    使用subprocess 模块为您提供了更多关于如何处理流程的选项。

    subprocess.call(['pdflatex', '--interaction', 'nonstopmode', '-shell-escape', packageName + '.tex'])
    

    您可以使用stdoutstderr 选项将这些输出重定向到管道或文件。

    如果要捕获程序的输出,请改用subprocess.check_output()

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 2011-03-04
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多