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
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
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', '
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.
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:]))'
> "
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
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'
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
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'
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
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', ...
11 matches
Mail list logo