0

I am trying to run

tcpflow -i any -C -g port 80 | grep -i "password1="

linux command using subprocess module in python. I am writing this like

proc = subprocess.Popen(["tcpflow", "-i", "any", "-C", "-g", "port", "80", "|", "grep", "-i", "'password1='"], stdout=subprocess.PIPE)

but it shows the error:

reportfilename: ./report.xml
tcpflow: 'password1=': No such device exists (SIOCGIFHWADDR: No such device)

But when I run the command in the terminal it runs perfectly. How can I resolve this issue?

furas
  • 134,197
  • 12
  • 106
  • 148
  • What you're doing there is running one command ("tcpflow") and passing all of those parameters to it, including the pipe "|" and "grep". If you want to set up a pipeline, then you either need to pass a single string and turn `shell=True` to have it interpret the piping, or run two `subprocess.Popen` and connect the stdin of the first to the stdout of the second. It's not that much more work, and it's arguably a better solution. – Tim Roberts May 20 '21 at 22:35
  • Thanks a lot @TimRoberts resolved it! – Sarib Ali Virk May 20 '21 at 22:39
  • it could run with `|` if you would use `shell=True` – furas May 20 '21 at 23:23
  • As others said, you need `shell=True`: [How to use \`subprocess\` command with pipes](https://stackoverflow.com/questions/13332268/how-to-use-subprocess-command-with-pipes) – paulsm4 May 20 '21 at 23:25

0 Answers0