How can I emulate curl with MS-DOS commands?

I am writing a cross-platform application that teaches people how to use the command line. I want to show them how to print the contents of an HTML URL. I usually used curl for this, but Windows does not come with this program, and I do not want my users to have to install any additional programs.

Is there a way to emulate curl using the built-in MS-DOS commands, perhaps to send a VBScript snippet to wscript ?

+4
source share
2 answers

Asuming.net is installed, you can combine C # with a batch file to create 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]); } } 
+5
source

Users have at least two options on Windows:

1) download curl-for-windows build (find it at http://curl.haxx.se/download.html ), some of them come as a single curl.exe file (or maybe with some ssl dll), so no installation required, you can simply copy to system32 or add to PATH

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

0
source

Source: https://habr.com/ru/post/1443907/


All Articles