I want a program that, with given arguments, I'm using optpatse, changes the working directory and executes some file.
I have tried with:
subprocess.check_call(['ls'], cwd="/home")
and this works. But if I do:
subprocess.call("cd", shell=True)
subprocess.call("ls", shell=True)
This doesn't work, the "ls"
shows me where the current python file is working. I understand that both commands get executed correctly, but I need the second one be executed at the directory from the first command.
def followpath(path):
subprocess.call("cd", shell=True)
subprocess.call("ls", shell=True)
#The real thing I want to execute is:
subprocess.call("cd", shell=True)
subprocess.call(["cd", path])
subprocess.call(["python3", somepyfile])
I expect also that, after running the script in the terminal, the working directory changes to the path and the somepyfile is executed.