4

I'm writing a cross-platform app that teaches people how to use the command line. I want to show them how to print out the HTML contents of a URL. Ordinarily, I would use curl for this, but Windows doesn't come with this program, and I don't want my users to have to install any extra programs.

Is there a way to emulate curl using built-in MS-DOS commands, perhaps sending a snippet of VBScript to wscript to be evaluated?

mcandre
  • 22,868
  • 20
  • 88
  • 147

2 Answers2

5

Asuming .net is installed, you can combine c# with a batch file to create a 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]);
    }
}
wimh
  • 15,072
  • 6
  • 47
  • 98
  • 1
    I'd like to avoid the 'cls', but I haven't discovered a way. If you play around with it you'll see that 'cls' hides an ugly but benign error message: `'/*' is not recognized as an internal or external command` – Core Jul 21 '16 at 22:22
0

Users have at least two possibilities on Windows:

1) download curl-for-windows build (search for it on http://curl.haxx.se/download.html), some of them come as single curl.exe file (or maybe with some ssl dll's), so do not require installation, you may just copy to system32 or add to PATH

2) install powershell and use corresponding .net objects to do the thing: http://answers.oreilly.com/topic/2006-how-to-download-a-file-from-the-internet-with-windows-powershell/

Anton
  • 827
  • 5
  • 8
  • > I don't want my users to have to install any extra programs. – mcandre Nov 04 '12 at 06:40
  • http://stackoverflow.com/a/10403427/1392001 - then this is the answer to your question. I just thought that copying curl is not installation, and PowerShell is the modern Windows shell which users are encouraged to use instead of cmd. :) – Anton Nov 04 '12 at 07:21