Execute a system command: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: `communicate()` is a safer method in general than `stdout.read()`, `stdin.write()`, etc) |
|||
Line 366: | Line 366: | ||
{{works with|Python|2.4 (and above)}} |
{{works with|Python|2.4 (and above)}} |
||
from subprocess import PIPE, Popen, STDOUT |
|||
p = Popen('ls', stdout=PIPE, stderr=STDOUT) |
|||
print |
print p.communicate()[0] |
||
'''Note:''' The latter is the preferred method for calling external processes, although cumbersome, it gives you finer control over the process. |
'''Note:''' The latter is the preferred method for calling external processes, although cumbersome, it gives you finer control over the process. |