I'm writing a python (2.7) script where I have to execute some shell commands which will send UDP packets to a remote VM. To execute the command, I'm using the subprocess lib and using both Popen and call methods.
The following code shows my 2 approaches to send a UDP packet. The problem is, neither of them (call or Popen) work (nor does os.system, for the matter). The command is interpreted as a single echo of the string "hello > /dev/udp/192.168.85.36/3000", as shown when I print the output from the PIPE.
myCmd = 'echo hello > /dev/udp/192.168.85.36/3000'
subprocess.call(myCmd, shell=True)
subprocess.Popen(myCmd.split(), stderr=subprocess.PIPE,\
stdout=subprocess.PIPE)
subprocess.Popen(['echo', 'packet', '>','/dev/udp/192.168.85.36/3000'],\
shell=False, stderr=subprocess.PIPE,stdout=subprocess.PIPE)
The interesting thing is that when I execute the exact same command directly in a terminal, the UDP packet is received in the remote VM. The difference is that inside the program, the echo command is inside a loop, executing multiple times (which is the expected behaviour). Any ideas?