为什么 subprocess.Popen 不起作用

发布于 2024-12-10 22:46:34 字数 1044 浏览 4 评论 0原文

我尝试了很多事情,但由于某种原因我无法让事情发挥作用。我正在尝试使用 Python 脚本运行 MS VS 的 dumpbin 实用程序。

以下是我尝试过的(以及对我不起作用的)

1.2.3

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()

.

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = 'C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()

kernel32.dll

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
process = subprocess.Popen(['C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin\\dumpbin', '/EXPORTS', dllFilePath], stdout = tempFile)
process.wait()
tempFile.close()

有人知道我正在尝试做的事情吗(dumpbin /EXPORTS C:\Windows\system32\ > tempfile.txt) 在Python中正确吗?

I tried a lot of things but for some reason I could not get things working. I am trying to run dumpbin utility of MS VS using a Python script.

Here are what I tried (and what did not work for me)

1.

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()

2.

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = 'C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()

3.

tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
process = subprocess.Popen(['C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin\\dumpbin', '/EXPORTS', dllFilePath], stdout = tempFile)
process.wait()
tempFile.close()

does anyone have any idea on doing what i am trying to do (dumpbin /EXPORTS C:\Windows\system32\kernel32.dll > tempfile.txt) correctly in Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坦然微笑 2024-12-17 22:46:34

Popen 的参数模式需要一个用于非 shell 调用的字符串列表和一个用于 shell 调用的字符串。这很容易解决。给定:

>>> command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath

使用 shell=True 调用 subprocess.Popen

>>> process = subprocess.Popen(command, stdout=tempFile, shell=True)

或使用 shlex.split 创建参数列表:

>>> process = subprocess.Popen(shlex.split(command), stdout=tempFile)

The argument pattern for Popen expect a list of strings for non-shell calls and a string for shell calls. This is easy to fix. Given:

>>> command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath

Either call subprocess.Popen with shell=True:

>>> process = subprocess.Popen(command, stdout=tempFile, shell=True)

or use shlex.split to create an argument list:

>>> process = subprocess.Popen(shlex.split(command), stdout=tempFile)
十六岁半 2024-12-17 22:46:34
with tempFile:
    subprocess.check_call([
        r'C:\Program Files\Microsoft Visual Studio 8\VC\bin\dumpbin.exe',
        '/EXPORTS', 
        dllFilePath], stdout=tempFile)
with tempFile:
    subprocess.check_call([
        r'C:\Program Files\Microsoft Visual Studio 8\VC\bin\dumpbin.exe',
        '/EXPORTS', 
        dllFilePath], stdout=tempFile)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文