tags:

views:

52

answers:

3

I have external script (sh), i would like to do something like this:

arg1 = 'some string'
arg2 = 'some string2'
arg3 = ''

cmd = ['/usr/local/bin/myscript', 'arg1', 'arg2', 'arg3']
Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)

I seems, that if "arg3" is empty, my script i called only with two arguments, how can I pass "arg3" event if it's empty?

A: 

Edited:

Popen(cmd[0] + [ repr(x) for x in cmd[1:]], shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)
Paulo Scardine
repr() works fine, for arguments, but there is a problem with first element which is a path to script
Maciej Kucharz
+2  A: 

test.py:

import sys
print(sys.argv)

test2.py:

import subprocess
import shlex

cmd="test.py 'some string' 'some string2' '' "
proc=subprocess.Popen(shlex.split(cmd))

Running test2.py yields

['test.py', 'some string', 'some string2', '']
unutbu
A: 

Mayby arg3 = '""' ?

Tony Veijalainen