[Tutor] Fwd: Executing a command from a specific directory

Patrick Sabin patrick.just4fun at gmail.com
Wed Sep 16 09:25:49 CEST 2009


Ansuman Dash schrieb:
> 
> Hello Everybody,
> 
> In Python scripting, how can I execute a command (which can be run from 
> spcific directory) and then retrieve the result (after executing the 
> command it give the command is executed successfull or not), so that I 
> can validate it.
> 
> Thanks,
> AD
> 
> 

import os
import subprocess

os.chdir('/your/directory')
p = subprocess.Popen("ls -l", shell=True, stdout=subprocess.PIPE)
out = p.stdout.read()
print out

- Patrick



More information about the Tutor mailing list