Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
cmd = "sudo start service/newservice db=temp"
p = subprocess.Popen(shlex.split(cmd), stderr=subprocess.STDOUT)
Above command works fine and intented process is spawned.
cmd = "sudo stop service/newservice db=temp"
p = subprocess.Popen(shlex.split(cmd), stderr=subprocess.STDOUT)
In the same file when above is called. It gives error.
traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1213, in _execute_child
raise child_exception
TypeError: must be encoded string without NULL bytes, not str
–
–
I got it solved. I only converted cmd to str before passing it to shlex.split, this is good esp when you receive some input this way:
cmd = "sudo stop service/newservice db=" + db
Safer practice is to convert it to string anyway.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.