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
  • 442
  • 6
  • 20

2 Answers2

4

You probably want to do

subprocess.call(["path/to/app"] + arg)
sloth
  • 95,484
  • 19
  • 164
  • 210
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
  • 83,651
  • 23
  • 134
  • 142