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)
ls -llist all items in current directory default. You could tell commandls -lwhich directory to list by usingls -l /your-path