Popen创建新目录

2024-09-28 19:26:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道我可以用操作系统模块创建一个新目录。但我试图用subprocess模块创建一个新目录,如下所示:

p=subprocess.Popen("mkdir extractions", shell=True)
os.chdir("extractions")

当脚本执行时,我注意到目录extractions已创建,但下一个os.chdir调用失败,说明目录extractions不存在。我知道我在使用子流程时遗漏了一些东西,这使得下一行不知道创建的目录。请帮忙!


Tags: 模块目录脚本trueos流程shellsubprocess