1

I have a file that needs to be passed some arguments to start executing a process. The file is ../main/serv. If I execute this command in unix shell terminal everything goes alright.

../main/serv -o phy=dhc=file:serv:1 -o in=dhc,0 -o out=file:phy_out:1 -o eui48=01:00:00:00:00:00

I call this function from my python script to start the process but doesn't work.

    subprocess.call(["../main/serv", "phy=", "dhc=file:serv:1", "in=", "dhc,0", "out=" , "file:phy_out:1", "eui48=01:00:00:00:00:00"])

I've been searching for a solution but I din't find it, I think that I'm not passing correctly the arguments, how can I do it?

Thank you!

Nkolot
  • 87
  • 2
  • 9
  • Although it's supposed to be insecure I tend to use os.system for these kind of messy calls. – Simon Hobbs Feb 26 '19 at 16:08
  • https://stackoverflow.com/questions/43022687/python-subprocess-argument-with-equal-sign-and-space and https://stackoverflow.com/questions/4091242/subprocess-call-requiring-all-parameters-to-be-separated-by-commas might help – Luke DeLuccia Feb 26 '19 at 16:11
  • Why don't you just split the command line passing all parameters as they are: `subprocess.call(["../main/serv", "-o", "phy=dhc=file:serv:1", "-o", "in=dhc,0", "-o", "out=file:phy_out:1", "-o", "eui48=01:00:00:00:00:00])` – Serge Ballesta Feb 26 '19 at 16:24

1 Answers1

0

I think that I'm not passing correctly the arguments, how can I do it?

Just pass the same arguments which you passed when you executed the command in the shell, so change that

    subprocess.call(["../main/serv", "phy=", "dhc=file:serv:1", "in=", "dhc,0", "out=" , "file:phy_out:1", "eui48=01:00:00:00:00:00"])

to

    subprocess.call(["../main/serv", "-o", "phy=dhc=file:serv:1", "-o", "in=dhc,0", "-o", "out=file:phy_out:1", "-o", "eui48=01:00:00:00:00:00"])
Armali
  • 18,255
  • 14
  • 57
  • 171