为什么在python子进程中没有正确传递十六进制数字

use*_*843 1 python hex subprocess parameter-passing

我无法使用python subprocess.Popen来插入模式...使用2.6.

测试:打开python解释器......

import subprocess
a = subprocess.Popen(['ping', '-c 1', '-p ff', '172.16.1.1'],subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)

结果... ping:模式必须指定为十六进制数字.

我已经将ff替换为:"f","23",23,0x23和一系列事物.我只是想看看shell认为它的结果.但是shell = True并没有像我预期的那样,a.communicate()给出(无,无)

Mar*_*cny 6

确保将所有"单词"拆分为自己的列表条目:

a = subprocess.Popen(['ping', '-c', '1', '-p' 'ff', '172.16.1.1'],subprocess.PIPE)
# PING 172.16.1.1 (172.16.1.1) 56(84) bytes of data.
Run Code Online (Sandbox Code Playgroud)

你拥有它的方式,你的命令被执行为

ping -c\ 1 -p\ ff 172.16.1.1
Run Code Online (Sandbox Code Playgroud)

(args之间的空格及其值被转义)