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

时间:2016-06-23 13:25:45

标签: python python-2.7 subprocess

亲爱的pythonists我有一些python模块调用的software.exe可执行文件。此software.exe创建新文件作为输出。 我想移动其中一个名为" whatever.xml' to anotherFolder我怎样才能刷新"目录内容? 以下代码仅考虑以前的状态,无法找到新生成的文件。 感谢

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

1 个答案:

答案 0 :(得分:1)

Popen没有阻止所以在你打电话复制之前可能没有创建文件,你可以调用.communicate()或者只使用check_call,它不会返回,直到过程完成。

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