I'm surprised you had any success running ls and rmdir without shell=True. You got "'STDOUT' is not defined" because you must either: from subprocess import STDOUT or you must refer to STDOUT as subprocess.STDOUT. P = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) But, the following seems to work fine with wget but with wget it seems to make errors whatever you do. This one is not good enough either: p = Popen(cmd, stdout=PIPE, stderr=PIPE) Python says: NameError: name 'STDOUT' is not defined There is error here: p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) I just took my example from the Replacing os.popen* section in the docs. This looks like an interesting alternative. (Disclaimer: I wrote it.) They let you do some cool things. That way you wait for the output until the process has actually completed.Īlso, take a look at the Process objects in the cliutils package. Here's a cleaner way: from subprocess import Popen, PIPE
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |