Reputation: 12924
So i have this application thats rather complicated... To keep it short this is the main things you should know:
file_name = raw_input("Name your file:").lower()
os.popen(sudo tcpdump -c5 -vvv -w "file_name" host wiki or host wiki2)
but this doesn't seem to work. Can i get a fix? Thanks, Pastelinux
edit1: Alright this is what i have now, but its not working, any pointers on how to fix?
import subprocess, os, sys
filename = raw_input('File name:').lower
pipe = os.popen("sudo tcpdump -c5 -w", 'filename')
pipe = popen("sudo tcpdump -c5 -w", shell=True, stdout=PIPE).stdout
Upvotes: 1
Views: 10044
Reputation: 66729
If you are running newer versions of Python, then use subprocess module.
See the replacement details of os.popen at :
It says: On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as the command to execute, in which case arguments will be passed directly to the program without shell intervention.
pipe = os.popen("cmd", 'r', bufsize)
==>
pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
Upvotes: 0
Reputation: 76965
Your problem is you don't pass a string as your command. Fixed call to popen()
:
os.popen('sudo tcpdump -c5 -vvv -w {0} host wiki or host wiki2'.format(file_name))
Upvotes: 3
Reputation: 131767
Don't use `os.popen', you should use the subprocess module.
I am assuming this (a string):
sudo tcpdump -c5 -vvv -w "file_name" host wiki or host wiki2
is your command.
Since we just need to call tcpdump and not get any output from it, we use subprocess.call
>>> subprocess.call(your_command.split())
Of course why it is not working depends on what the error is, but this is how you should go about it. If you can update the answer with your error, then it can be clear.
Upvotes: 3