Execute a system command: Difference between revisions

m
→‎{{header|Python}}: `communicate()` is a safer method in general than `stdout.read()`, `stdin.write()`, etc
m (→‎{{header|Python}}: `communicate()` is a safer method in general than `stdout.read()`, `stdin.write()`, etc)
Line 366:
 
{{works with|Python|2.4 (and above)}}
importfrom subprocess import PIPE, Popen, STDOUT
outputp = subprocess.Popen('ls', shellstdout=TruePIPE, stdoutstderr=subprocess.PIPESTDOUT).stdout
print outputp.readcommunicate()[0]
 
'''Note:''' The latter is the preferred method for calling external processes, although cumbersome, it gives you finer control over the process.
A
59

edits