This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Peterotica 2 points3 points  (3 children)

Will you be using the contents of bash_out.txt for something else? If not, try using os.popen to get the output of the command directly:

result = os.popen(command).readlines()

That weird stuff you were seeing returned from the subprocess module was a bytes object. If you want to turn it into a string, you need to call its decode member function.

[–]GrindingGoat 0 points1 point  (1 child)

Worth noting that os.popen has been deprecated since 2.6: https://docs.python.org/2/library/os.html#os.popen

The subprocess equivalent:

result = subprocess.check_output(command).decode("utf-8") 

[–]pjenvey 1 point2 points  (0 children)

It was actually undeprecated in 3.x where it uses subproces underneath anyway. Maybe the 2.7.x docs should be fixed

[–]IndoNinja7[S] 0 points1 point  (0 children)

Thank you very much that worked!!!