Python fabric quotes issue -
spent more 30 mins of time in trying different possibly. i'm exhausted. can please me on quote problem
def remote_shell_func_execute(): settings(host_string='user@xxx.yyy.com',warn_only=true): process = run("subprocess.popen(\["/root/test/shell_script_for_test.sh func2"\],shell=true,stdin=subprocess.pipe,stdout=subprocess.pipe,stderr=subprocess.pipe)") process.wait() line in process.stdout.readlines(): print(line)
when run fab, get
fab remote_shell_func_execute traceback (most recent call last): file "/usr/local/lib/python2.7/site-packages/fabric-1.6.1-py2.7.egg/fabric/main.py",line 654, in main docstring, callables, default = load_fabfile(fabfile) file "/usr/local/lib/python2.7/site-packages/fabric-1.6.1-py2.7.egg/fabric/main.py",line 165, in load_fabfile imported = importer(os.path.splitext(fabfile)[0]) file "/home/fabfile.py", line 18 process = run("subprocess.popen(\["/root/test/shell_script_for_test.sh func2"\],shell=true,stdin=subprocess.pipe,stdout=subprocess.pipe,stderr=subprocess.pipe)") ^ syntaxerror: invalid syntax
just use single quoted string.
run('subprocess.popen(\["/root/test/shell_script_for_test.sh func2"\],shell=true,stdin=subprocess.pipe,stdout=subprocess.pipe,stderr=subprocess.pipe)')
or escape inner "
.
run("subprocess.popen(\[\"/root/test/shell_script_for_test.sh func2\"\],shell=true,stdin=subprocess.pipe,stdout=subprocess.pipe,stderr=subprocess.pipe)")
Comments
Post a Comment