停止 cmd 提示直到下载完成

Stalling the cmd prompt till a download is complete

我正在尝试从命令提示符下载并安装 python。我有下载和安装命令。问题是我希望 cmd 等到下载结束,然后再执行安装命令。

我正在使用 python 脚本及其子进程模块执行上述操作,因此我的代码看起来像这样(这些不是确切的命令):

subprocess.call('start /max http://profile.org/choice/fileW.msi' , shell = True)
subprocess.call('msiexec.exe fileW.msi' , shell = True)

第一行下载 python.msi 文件。第二行安装 python.msi。当我 运行 它们分开时它们可以工作,但是当我 运行 它们在一起时我得到 "fileW.msi not found"。原因是在下载 .msi 之前,cmd 运行s 第二个命令,结果找不到文件,因为它尚未下载。

一般答案:既然你需要 /max,你就需要 start,但是 start 在后台启动,除非你使用 /wait 开关

但在你的情况下,这不起作用,因为字符串是 URL 并且 windows 选择你的默认浏览器打开/下载它,所以你不能在下载之前阻止调用已经结束。

另一个解决方案是使用 wget 包:

import wget
downloaded_file = wget.download("http://profile.org/choice/fileW.msi")
subprocess.call(['msiexec.exe',downloaded_file])