如何使用MS-DOS命令模拟卷曲



我正在编写一个跨平台应用程序,该应用教会人们如何使用命令行。我想向他们展示如何打印出URL的HTML内容。通常,我将使用curl为此,但是Windows并不随附此程序,我不希望我的用户必须安装任何额外的程序。

是否有一种方法可以使用内置的MS-DOS命令模拟卷曲,也许将VBScript的摘要发送到要评估的wscript

已安装了.net,您可以将C#与批处理文件组合在一起以创建wget.cmd:

/*
@echo off && cls
if '%2'=='' (
  echo usage: %0 url filename
  goto :eof
)
set WinDirNet=%WinDir%Microsoft.NETFramework
IF EXIST "%WinDirNet%v2.0.50727csc.exe" set csc="%WinDirNet%v2.0.50727csc.exe"
IF EXIST "%WinDirNet%v3.5csc.exe" set csc="%WinDirNet%v3.5csc.exe"
IF EXIST "%WinDirNet%v4.0.30319csc.exe" set csc="%WinDirNet%v4.0.30319csc.exe"
%csc% /nologo /out:"%~0.exe" %0
"%~0.exe" "%1" "%2"
del "%~0.exe"
goto :eof
*/
using System;
using System.Net;
using System.IO;
class MyWget
{
    static void Main(string[] args)
    {
        WebClient wc = new WebClient();
        wc.DownloadFile(args[0],args[1]);
    }
}

用户在Windows上至少有两个可能性:

1)下载curl-for-windows构建(在http://curl.haxx.se/download.html上搜索它,其中一些作为单个curl.exe文件(或某些SSL DLL)来,因此不需要安装,您只需复制到System32或添加到路径

2)安装PowerShell并使用相应的.NET对象来执行此操作:http://answers.oreilly.com/topic/2006-how-to-download-a-file-file-from-the-internet-with-with-windows-powershell/

最新更新