How to input a string as argv in python? -


i'm debugging python program named test.py this:

#!/bin/env python import sys print sys.argv[1] 

when enter command, result confuse:

[root@yf-mos-test-net09 ~]# python test.py "{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "ping -c 1 8.8.8.8"]}]}}" 

result is:

{execute: guest-execute, session: 4768, arguments: {commands: [{command: /bin/sh, arguments: [sh, -c, ping 

what expect should be:

{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "ping -c 1 8.8.8.8"]}]}} 

how fix this? there wrong in param or wrong in program? thank you~

it's understanding of shell failing here :)

what should use different quotes or escape them.

try instance (notice single quote around json):

[root@yf-mos-test-net09 ~]# python test.py '{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "ping -c 1 8.8.8.8"]}]}}' 

but depend on shell using.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -