0

I'm debugging a python program named test.py as this:

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

when I enter this command, result is 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 I expect should be:

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

How to fix this? Is there something wrong in my param or something wrong in my program? Thank you~

1 Answer 1

3

It's actually your understanding of the shell that is failing you here :)

What you should do is use different quotes or escape them.

Try this for instance (notice the single quote around the 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 it will probably depend on what shell you are using.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.