使用python在可执行文件上运行批处理命令

2024-04-23 16:24:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我用这段代码来启动批处理文件,但是

import os
os.startfile("C:\Documents and Settings\Zha\Desktop\Strings\strings.exe ")

在字符串.exe从cmd打开批处理命令时运行它,如下所示:

^{pr2}$

我需要从python运行它。可能的解决方法?在


Tags: and文件字符串代码importcmdsettingsos
1条回答
网友
1楼 · 发布于 2024-04-23 16:24:26
from subprocess import Popen, PIPE

handle = Popen(['strings', '-q', 'C:\\Documents and Settings\\Zha\\Desktop\\folder\\*'], stdout=PIPE)

while handle.poll() is None:
    print(handle.stdout.readline())
handle.stdout.close()

相关问题 更多 >