0

I want to use subprocess to open an application. However the amount of argument is not fixed. What's the best way to approach this?

subprocess.call( "path/to/app", arg[0], arg[1], arg... )

minimum arg[] is 1 but it can get as large and 10 or 20. What's the best way to send them to aubprocess's argument in this case?

Panupat
  • 452
  • 6
  • 21

2 Answers2

4

You probably want to do

subprocess.call(["path/to/app"] + arg)
sloth
  • 99,095
  • 21
  • 171
  • 219
1

There is only one argument, and it's a list:

>>> subprocess.call(["ls", "-l"])
0

Taken directly from the examples at http://docs.python.org/library/subprocess.html#subprocess.call

You should be doing subprocess.call(["path/to/app", arg[0], arg[1], arg... ]), for example:

subprocess.call(["path/to/app"]+arg)
ninjagecko
  • 88,546
  • 24
  • 137
  • 145