如何将.txt文件arg传递给exe应用程序?

时间:2018-11-08 23:28:06

标签: python python-3.x

我需要将.txt文件与.exe应用程序结合在一起。当我在.exe应用程序上移动.txt时,此过程可以在我的桌面上正常工作。我可以用python吗?

1 个答案:

答案 0 :(得分:1)

是的,你只是做

from subprocess import call
call(["that.exe", "that.txt"])

import os
os.system("that.exe that.txt")

编辑:

也许您需要调用cmd \c来运行exe?

from subprocess import call
call(["cmd", "/c", "that.exe", "that.txt"])

import os
os.system("cmd /c that.exe that.txt")

编辑:

如果要在调用后将击键发送给进程,则可以使用子进程来获取可以进行后续操作的对象。

import subprocess
proc = subprocess.Popen(["cmd", "/c", "that.exe", "that.txt"], shell=True)
proc.communicate(input=b'\n')

最终编辑:

您可能需要在其上使用stdin = subprocess.PIPE ...

import subprocess
proc = subprocess.Popen(["cmd", "/c", "that.exe", "that.txt"] ,stdin=subprocess.PIPE)
proc.communicate(input=b'\n')
相关问题