4

コマンドラインの使い方を教えるクロスプラットフォームアプリを書いています。URL の HTML コンテンツを出力する方法を彼らに示したいと思います。通常はこれを使用curlしますが、Windows にはこのプログラムが付属していないため、ユーザーが追加のプログラムをインストールする必要はありません。

組み込みの MS-DOS コマンドを使用して curl をエミュレートする方法はありますか?おそらく VBScript のスニペットを送信してwscript評価することはできますか?

4

2 に答える 2

5

.net がインストールされていると仮定すると、c# とバッチ ファイルを組み合わせて wget.cmd を作成できます

/*
@echo off && cls

if '%2'=='' (
  echo usage: %0 url filename
  goto :eof
)

set WinDirNet=%WinDir%\Microsoft.NET\Framework
IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.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]);
    }
}
于 2012-11-04T11:12:20.120 に答える
0

Windows では、少なくとも 2 つの可能性があります。

1) curl-for-windows ビルドをダウンロード ( http://curl.haxx.se/download.htmlで検索)インストールは不要です。system32 にコピーするか、PATH に追加するだけです。

2) powershell をインストールし、対応する .net オブジェクトを使用して実行します: http://answers.oreilly.com/topic/2006-how-to-download-a-file-from-the-internet-with-windows-powershell /

于 2012-11-04T06:29:59.150 に答える