How can I delay execution until after os.system finishes?

随声附和 提交于 2019-12-02 09:05:30

The first thing I'd try is to use shutil.copyfile() instead of an external program to copy the file. If you have to use an external program, you should call it via subprocess.Popen(), not via os.system(). You can use the Popen.wait() to wait for the subprocess to finish.

I think you should rather use shutil.copyfile than os.system to copy a file.

(Edit: woops, copy, not move)

use the shutil module for copying files.

The shutil module offers a number of high-level operations on files and collections of files. In particular, functions are provided which support file copying and removal.

also, use the subprocess module instead of os.system()

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several other, older modules and functions, such as:

os.system

for a better answer, you need to provide more detail about what exactly you are trying to do and how (programmatically) you are stuck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!