i have to execute a command use python subprocess .
by default , command is execute as working on the directory where the python script file is . such as
subprocess.Popen(shlex.split("ls -l"))
will list the file in the directory of the script file where is .
but i want this command to execute in another directory ,say , B . how can i do it .
i try this , but faild:
env['PWD'] = "/data/a"
f = tempfile.TemporaryFile('w+b')
p = subprocess.Popen(shlex.split(cmd),stdout= f,stderr=f,env=env)
asked Mar 30, 2011 at 7:02
mike
1,1474 gold badges17 silver badges37 bronze badges
3 Answers 3
ls -l list all items in current directory default. You could tell command ls -l which directory to list by using ls -l /your-path
answered Mar 30, 2011 at 7:19
Jason
3,3475 gold badges29 silver badges28 bronze badges
Comments
hi did u try changing the unix command
ls -l
to something like
ls -l /usr/share;
answered Mar 30, 2011 at 7:08
Anuj
9,6729 gold badges35 silver badges30 bronze badges
lang-py