subprocess - multiple argument from terminal using python -


I'm able to run it properly using os.system. It is writing the PPP file in the text.

  os.system ("tshark -z 'proto, colinfo, tcp.srcport, tcp.srcport' -r filename.papp & gt; testfile ')  

But when I tried to extract the input file from the terminal, I got the following error: tshark: -z Invalid argument

  host = raw_input ("Enter file name:") Exam = Subprocess.Popen (["Tasker", "- z", "Proto, Colinfo, TCP. SRCport, TCP. SRCport", "- R", Host, "& gt;", "TestFile"], Stdout = subprocess .PIPE) output = test.communicate () [0]  

Can anyone understand this Is that I'm making a mistake?

osc system , use the shell = true parameter to subprocess.open and provide the same command string (not an array of strings):

 < Code> subprocess.Popen ("Tshark -J 'proto, colinfo, TCP SRCport, TCP SRCport' -R + + + +> & gt; TestFile", standout = subprocess.ppe, shell = true)  

you a shell Minister needs to explain your command line because you are using a file output redirection ( "> testfile").

In your example, you are passing each element of the string list into execve () system call and therefore -z as argument for tshark as the parameter of the command (which becomes 'Proto, Colinfo, TCP. SRCport, TCP SRCport' ) proto, colinfo, tcp.srcport, tcp.srcport Option instead of & which & gt; What to do with the and testfile , arguments).

As with wnnmaw point user input ( with shell = true with ossystem or subprocess.> Host variable in your case) allows a user to pass educational data to the shell. It can be used to execute (potentially bad) commands on your system.

For example, setting host to in your example; / Bin / rm -rf / will delete every file on a Unix system (the user running this process has sufficient privileges).

Therefore it is very important to validate user input before adding it to the command string.


Comments