Skip to main content
 首页 » 编程设计

python之subprocess.call cd 不工作

2025年05月04日9kuangbin

<分区>

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 盒子里