簡體   English   中英

在 Windows 上使用 Python 運行可執行文件並提供文本文件作為輸入

[英]Run an executable and giving text file as input using Python on Windows

我可以編寫代碼但在調用可執行文件后凍結。 我已經在 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 時,它會凍結。 任何人都可以提供任何意見嗎?

首先,您應該嘗試從命令提示符運行它,看看它是否是 exe 的問題。 如果它在 cmd 提示符下工作,接下來要看的是它是否在等待任何輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM