如何使用 subprocess.Popen 更新目录以在 Python 中查找新文件

How to update directory to look for new files in Python using subprocess.Popen

亲爱的 pythonists 我有一些 software.exe 可执行文件被 python 模块调用。 software.exe 创建新文件作为输出。 我想将其中一个名为 "whatever.xml' to anotherFolder how can I "refresh" 的文件移动到目录内容? 下面的代码只考虑之前的状态,无法找到新生成的文件。 谢谢

subprocess.Popen('sofware.exe')
shutil.copy( 'whatever.xml' , anotherFolder )

Popen 不会阻塞,因此在您调用复制之前可能不会创建文件,您可以调用 .communicate() 或只使用 check_call,在过程完成之前不会 return。

subprocess.check_call('sofware.exe')
shutil.copy( 'whatever.xml' , anotherFolder )