从 URL 下载 Windows 批处理文件 [英] Windows batch file file download from a URL

查看:58
本文介绍了从 URL 下载 Windows 批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网站下载文件(例如 http://www.example.com/package.zip) 使用 Windows 批处理文件.我在编写以下函数时收到错误代码:

I am trying to download a file from a website (ex. http://www.example.com/package.zip) using a Windows batch file. I am getting an error code when I write the function below:

xcopy /E /Y "http://www.example.com/package.zip"

批处理文件似乎不喜欢 http 后面的/".有没有办法转义这些字符,使其不假定它们是函数参数?

The batch file doesn't seem to like the "/" after the http. Are there any ways to escape those characters so it doesn't assume they are function parameters?

推荐答案

使用 PowerShell 2.0(预装 Windows 7),您可以使用:

With PowerShell 2.0 (Windows 7 preinstalled) you can use:

(New-Object Net.WebClient).DownloadFile('http://www.example.com/package.zip', 'package.zip')

从 PowerShell 3.0(预装 Windows 8)开始,您可以使用 Invoke-WebRequest:

Starting with PowerShell 3.0 (Windows 8 preinstalled) you can use Invoke-WebRequest:

Invoke-WebRequest http://www.example.com/package.zip -OutFile package.zip

从批处理文件中调用它们:

From a batch file they are called:

powershell -Command "(New-Object Net.WebClient).DownloadFile('http://www.example.com/package.zip', 'package.zip')"
powershell -Command "Invoke-WebRequest http://www.example.com/package.zip -OutFile package.zip"

(PowerShell 2.0 可在 XP 上安装,3.0 可用于 Windows 7)

(PowerShell 2.0 is available for installation on XP, 3.0 for Windows 7)

这篇关于从 URL 下载 Windows 批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆