In [3]: pwd
Out[3]: u'/Users/aarcher/Desktop/scripts'
In [5]: subprocess.call(['mkdir', '-p', os.path.expanduser('~/file/path/name')])
Out[5]: 0
我在另一个终端中验证它已成功创建 /Users/aarcher/file/path/name ,但无法更改到该目录,即使它返回 0:
In [7]: subprocess.call(['cd', os.path.expanduser('~/file/path/name')], shell=True)
Out[7]: 0
In [8]: pwd
Out[8]: u'/Users/aarcher/Desktop/scripts'
我在unix盒子里
subprocess.call()
创建一个new过程。 cd在该进程中工作,但当进程退出时,不会影响当前进程。这就是流程设计的工作原理。
如果您需要将脚本更改为不同的目录,您可以使用os.chdir https://docs.python.org/3.5/library/os.html#os.chdir这将更改当前进程的目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)