【问题标题】:Run an executable and giving text file as input using Python on Windows在 Windows 上使用 Python 运行可执行文件并提供文本文件作为输入
【发布时间】:2018-05-14 12:04:01
【问题描述】:

我可以编写代码,但在调用可执行文件后冻结。我在 StackOverflow 和其他任何地方都搜索过答案,但没有成功。
对于 Linux 和我在下面作为示例描述的相同代码,该问题已得到解答,但它不适用于 windows。任何意见都会有很大帮助。

import subprocess
for filename in 'inp1.txt', 'inp2.txt':   #input text files

    with open(filename) as infile, open('result_{}'.format(filename), 'w') as outfile:

       result = subprocess.run([r'C:\Users\Desktop\Python_files\file.exe'], stdin=infile, stdout=outfile) # executable name is file.exe

当代码用于 Windows 时,它会冻结。任何人都可以提供任何意见吗?

【问题讨论】:

  • 可以发file.exe的内容吗?
  • 代码对我来说看起来不错。我的第一个猜测是file.exe 挂了。
  • 我没有 file.exe 的源代码,因为它是高度机密的。我只使用可执行文件。
  • 可能值得将 stderr 发送到某个地方,看看其中是否有任何线索。
  • @TomDalton 我认为代码在“result=.....”行中冻结,因此即使通过 stderr 也无济于事

标签: python python-3.x subprocess


【解决方案1】:

首先,你应该尝试从命令提示符运行它,看看是不是exe的问题。如果它在 cmd 提示符下工作,接下来要看的是它是否在等待任何输入。

【讨论】:

  • 我正在使用命令提示符并在名为 runner as>> py runner.py 的文件中运行上述脚本
  • 等待输入然后冻结
猜你喜欢
  • 1970-01-01
  • 2014-02-26
  • 2011-11-01
  • 2015-07-16
  • 1970-01-01
  • 2021-11-19
  • 2020-11-18
  • 2019-03-09
  • 1970-01-01
相关资源
最近更新 更多