- edited description
`shell_shlex` incorrect parse.
Issue #31
invalid
from sarge import shell_shlex, shell_format
import shlex
import subprocess
cmd = shell_format("python -c {0}", "print('ok')")
print("format: " + cmd)
try:
args_shlex = shlex.split(cmd)
print(args_shlex)
except:
print('except shlex.split!')
try:
args_shell_shlex = list(shell_shlex(cmd, control='();>|&'))
print(args_shell_shlex)
except:
print('except shell_shlex!')
Run this code:
C:\Users\pahaz_000>C:\Python27\python.exe z.py
format: python -c 'print('\''ok'\'')'
['python', '-c', "print('ok')"]
except shell_shlex!
As we can see, default shlex
parser work fine with this example.
Comments (4)
-
reporter -
reporter - marked as blocker
-
reporter Traceback (most recent call last): File "z.py", line 14, in <module> args_shell_shlex = list(shell_shlex(cmd, control='();>|&')) File "C:\Python27\lib\shlex.py", line 269, in next token = self.get_token() File "C:\Python27\lib\shlex.py", line 96, in get_token raw = self.read_token() File "C:\Python27\lib\site-packages\sarge\shlext.py", line 106, in read_token raise ValueError("No closing quotation") ValueError: No closing quotation
-
repo owner - changed status to invalid
I don't think this is a bug. You have to specify
posix=True
, and then it works as expected. - Log in to comment