Command line execution in different folder

后端 未结 3 1169
眼角桃花
眼角桃花 2020-12-10 00:20

I\'m calling a command line program in python using the os.system(command) call.

How can I call this command passing a different folder for execution? T

3条回答
  •  抹茶落季
    2020-12-10 01:05

    The subprocess module is a very good solution.

    import subprocess
    p = subprocess.Popen([command, argument1,...], cwd=working_directory)
    p.wait()
    

    It has also arguments for modifying environment variables, redirecting input/output to the calling program, etc.

提交回复
热议问题