子流程变量
1 import subprocess
2 raw = raw_input("Filename:").lower()
3 ip = raw_input("Host:").lower()
4 cmd = subprocess.call("tcpdump -c5 -vvv -w" + " raw " + " ip ",shell=True)
这就是我的脚本。除了使用原始输入的一个关键目标之外,一切都正常。 它允许我输入任何我想要的东西,但是当它保存文件或使用 ip/主机时,doe 实际上并没有做任何事情。 当然它给了我数据包,但是来自本地主机而不是我输入的主机。
我如何知道这不起作用是因为我的第一个原始输入是文件名,所以我进行了测试,当我查看文件夹时是我的脚本是,它生成一个名为“raw”的文件,意思是,它实际上并不只使用我的“X”中的内容来获取我的输入......
所以我有几次机会来实现这一点:
1 import subprocess
2 raw = raw_input("Filename:").lower()
3 ip = raw_input("Host:").lower()
4 cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw + "host" + ip,shell=True)
这很棒,因为它实际上需要-w 但现在将其保存为 rawhostip 而不是“raw”输入。 作为参考,该命令在终端中的外观如下:
tcpdump -c5 -vvv -w savename host wiki2
唯一的两个变量是 savename 和 wiki2,其余变量是命令正常工作所必需的。
使用此脚本我收到此错误:
import subprocess
raw = raw_input("Filename:").lower()
ip = raw_input("Host:").lower()
cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw, "host" + ip,shell=True)
错误:
Traceback (most recent call last):
File "te.py", line 4, in <module>
cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw, "host" + ip,shell=True)
File "/usr/lib/python2.6/subprocess.py", line 480, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 583, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
我迷路了。任何帮助都会很棒,是的,我知道在现场查看子流程的文档:X,我需要一个人来教我,我不明白我在读什么。
我的问题是如何处理这些变量。
1 import subprocess
2 raw = raw_input("Filename:").lower()
3 ip = raw_input("Host:").lower()
4 cmd = subprocess.call("tcpdump -c5 -vvv -w" + " raw " + " ip ",shell=True)
So this is my script. I everything works besides one key objective, using the raw input.
It allows me to input anything i want, but when it goes to saving the file or using an ip/host doe doesn't actually do anything.
Sure it gives me the packets, but from the localhost not the host i type in.
how i know this isn't working is cause my first raw input is the filename, so i put in test, when i look in the folder were my script is, it produces a file called "raw" meaning, its not actually taking my input only using whats inside my "X"...
So i make a few chances to come to this:
1 import subprocess
2 raw = raw_input("Filename:").lower()
3 ip = raw_input("Host:").lower()
4 cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw + "host" + ip,shell=True)
Which is great because it actually calls for the -w but it saves it now as rawhostip instead of "raw"s input.
for reference this is what the command looks like in the terminal:
tcpdump -c5 -vvv -w savename host wiki2
the only two variabls are savename and wiki2 the rest are needed for the command to work.
with this script i get this error:
import subprocess
raw = raw_input("Filename:").lower()
ip = raw_input("Host:").lower()
cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw, "host" + ip,shell=True)
Error:
Traceback (most recent call last):
File "te.py", line 4, in <module>
cmd = subprocess.call("tcpdump -c5 -vvv -w" + raw, "host" + ip,shell=True)
File "/usr/lib/python2.6/subprocess.py", line 480, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 583, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
I am at a lost. Any help will be great, yes I know look at subprocess's doc's on site:X, I have I need a human to teach me, I don't understand what I am reading.
My question is how do I work with these variables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用
shell=True
。这应该是False
。您在输入时犯了一些微妙的错误。具体来说,如果您有两个字符串:
请注意,
Hello
和Hi
之间没有空格。所以不要这样做。 (你的第 4 行)你应该做(好方法):
现在应该可以了。
Don't use
shell=True
. That should beFalse
.You are making subtle mistakes with the input. Specifically, if you have two strings:
Notice, there is no space between
Hello
andHi
. So don't do this. (Your line 4)You should do (the good way):
Now it should work.
您不应在
subprocess
函数中使用字符串形式。尝试:You should not use the string form ob the
subprocess
functions. Try: