Re: line to argv transformation

2014-06-17 Thread Antoon Pardon
On 16-06-14 13:09, Chris Angelico wrote: > On Mon, Jun 16, 2014 at 8:51 PM, Tim Chase > wrote: >> On 2014-06-16 20:41, Chris Angelico wrote: >>> Oops! I made the cardinal error of trying in one and assuming it'd >>> work in both. Just needs a b prefix on the split string: >>> >>> def shell_split(c

Re: line to argv transformation

2014-06-16 Thread Tim Chase
On 2014-06-16 13:51, Antoon Pardon wrote: > >>> shlex.split("ls *.py") > ['ls', '*.py'] > >>> shlex.split("ls '*.py'") > ['ls', '*.py'] To accommodate this, I'd probably just clone the shlib.py to my local project under a new name and then tweak the source to emit whether a token was quoted or

Re: line to argv transformation

2014-06-16 Thread Antoon Pardon
On 16-06-14 13:01, Peter Otten wrote: > Antoon Pardon wrote: > >> I am looking for an interface that takes a string as argument. The >> string is to be treated as if it is a command line and transformed into >> an argv list. >> >> "ls file" -> ['ls', 'file'] >> "ls *.py" -> ['ls', 'file1.py', '

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> def shell_split(cmd): >> return subprocess.check_output("""python -c 'import sys; >> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0") >> >> You'll get back a list of byte strings, in any case.

Re: line to argv transformation

2014-06-16 Thread Tim Chase
On 2014-06-16 20:41, Chris Angelico wrote: > Oops! I made the cardinal error of trying in one and assuming it'd > work in both. Just needs a b prefix on the split string: > > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' > "

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:51 PM, Tim Chase wrote: > On 2014-06-16 20:41, Chris Angelico wrote: >> Oops! I made the cardinal error of trying in one and assuming it'd >> work in both. Just needs a b prefix on the split string: >> >> def shell_split(cmd): >> return subprocess.check_output("""pyth

Re: line to argv transformation

2014-06-16 Thread Peter Otten
Antoon Pardon wrote: > I am looking for an interface that takes a string as argument. The > string is to be treated as if it is a command line and transformed into > an argv list. > > "ls file" -> ['ls', 'file'] > "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...] > "ls '*.py'" -> ['ls', '*.py'

Re: line to argv transformation

2014-06-16 Thread Marko Rauhamaa
Chris Angelico : > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0") > > You'll get back a list of byte strings, in any case. Feel free to pass > them through a decode operation, or to incor

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:24 PM, Antoon Pardon wrote: > On 16-06-14 12:06, Chris Angelico wrote: > >> def shell_split(cmd): >> return subprocess.check_output("""python -c 'import sys; >> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0") > > Nice idea, unfortunatly it doesn'

Re: line to argv transformation

2014-06-16 Thread Antoon Pardon
On 16-06-14 12:06, Chris Angelico wrote: > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0") Nice idea, unfortunatly it doesn't work in python3.3 >>> shell_split("ls *.py") Traceback (most

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 7:56 PM, Antoon Pardon wrote: > I am looking for an interface that takes a string as argument. The > string is to be treated as if it is a command line and transformed into > an argv list. > > "ls file" -> ['ls', 'file'] > "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...