gpt4 book ai didi

python - 如何在 python Popen 中将 args 传递给 args?

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:52 24 4
gpt4 key购买 nike

import subprocess

command = ["wine"]

arguments = ['/root/Desktop/COLDHEART/exploits/eternalblue/Eternalblue-2.2.0.exe', ' --inconfig /root/Desktop/COLDHEART/exploits/eternalblue/Eternalblue-2.2.0.0.xml', '--targetip 0.0.0.0']

command.extend(arguments)

proc = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

print(proc)

print("\n Done")

所以我使用 subprocess.Popen 来获取命令的输出。从技术上讲,该命令运行 2 个程序:wine 和eternalblue.exe。我需要将参数传递给eternalblue.exe,但出现错误。它似乎接受我传递的任何参数并尝试将它们用于 wine 而不是 exe。

最佳答案

根据Python文档,

import shlex, subprocess
command_line = raw_input()
## /bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
args = shlex.split(command_line)
print args
##['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd',"echo '$MONEY'"]
p = subprocess.Popen(args) # Success!

您只需将参数分成两个元素。例如,' --inconfig/root/Desktop/COLDHEART/exploits/eternalblue/Eternalblue-2.2.0.0.xml' --> '--inconfig', '/root/Desktop/COLDHEART/exploits/eternalblue/Eternalblue-2.2.0.0. xml'

关于python - 如何在 python Popen 中将 args 传递给 args?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52574459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com