我通過Python腳本編寫的qemu QGA命令是這樣的:如何在python命令行中將此json字符串編寫爲param?
python cmd.py request:'{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "route | grep default | awk '{print $2}'"]}]}}'
但帕拉姆被解析成波紋管,其中devide從JSON字符串 '{打印$ 2}':
['cmd.py', 'request:{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "route | grep default | awk {print', '}"]}]}}']
實際我想這一點,這是awk {print'{print $2}'
shell命令在虛擬機中運行,而這種格式無法改變:
['cmd.py', 'request:{"execute": "guest-execute", "session": "4768", "arguments": {"commands": [{"command": "/bin/sh", "arguments": ["sh", "-c", "route | grep default | awk {print'{print $2}'}"]}]}}']
這可能嗎?如果不可能,這意味着我必須在cmd.py中手動構建json字符串?
謝謝〜
您必須刪除空格併爲您的引號使用反斜槓。這樣,你的整個json字符串將被視爲只有一個參數。 – iFlo