c# - Use wget command to download multiple files at different locations -
i want download multiple files www.google.com, yahoo.com , gmail.com @ 3 different locations using wget. how should go it? please me out..
i doing through c#:
processstartinfo startinfo = new processstartinfo("cmd.exe"); process p = new process(); startinfo.redirectstandardinput = true; startinfo.useshellexecute = false; startinfo.redirectstandardoutput = true; startinfo.redirectstandarderror = true; p = process.start(startinfo); p.standardinput.writeline(@"wget --output-document=c:\1.xml xyz.com/a.xml"); p.standardinput.writeline(@"wget --output-document=c:\2.xml xyz.com/b.xml"); p.standardinput.writeline(@"wget --output-document=c:\3.xml xyz.com/c.xml"); p.standardinput.writeline(@"exit"); string output = p.standardoutput.readtoend(); string error = p.standarderror.readtoend(); p.waitforexit(); p.close();
this not working. know if there r othe ways of downloading multiple files using wget..
if you're talking retrieving each file different location, still doing sequentially, change uri in wget
command point different location.
if want concurrent downloads rather sequential, have start 3 separate processes , have them download 1 file each. these ptocesses run side side i'd consider large files (of xml file not).
if you're having troubles getting commands run @ all, first thing ditch cmd.exe
, standard input. there's no reason why can't have process run wget
directly. or, if want start 1 process, output them temporary file , use single process cmd /c tempfile.cmd
run it.
however, there may totally different problem you're having unrelated you've shown, because exact code 3 echo
statements in place of wget
ones runs fine, generating correct output, @ least in visual c# express 2010.
and, in fact, once got gnuwin32 wget
on path, following worked well, getting real documents off net , placing them in top-level directory:
using system; using system.diagnostics; namespace consoleapplication1 { class program { static void main(string[] args) { processstartinfo startinfo = new processstartinfo("cmd.exe"); process p = new process(); startinfo.redirectstandardinput = true; startinfo.useshellexecute = false; startinfo.redirectstandardoutput = true; startinfo.redirectstandarderror = true; p = process.start(startinfo); p.standardinput.writeline( @"wget --output-document=c:\q1.txt http://www.ibm.com"); p.standardinput.writeline( @"wget --output-document=c:\q2.txt http://www.microsoft.com"); p.standardinput.writeline( @"wget --output-document=c:\q3.txt http://www.borland.com"); p.standardinput.writeline(@"exit"); string output = p.standardoutput.readtoend(); string error = p.standarderror.readtoend(); p.waitforexit(); p.close(); } } }
here's proof, single window partway through microsoft download:
so, bottom line, have shown not inherently unworkable evidenced image above. suggestion start looking around @ other things such version of wget
you're using, gnuwin32 or cygwin.
now, things interesting larger files, you've stated in 1 of comments. if change 3 uris http://download.microsoft.com/download/5/f/c/5fc4f80c-242d-423b-9a11-9510a013152d/dolphins.themepack
, file of 12,889,103 bytes, code above hangs @ 18% of first download (around 2.3m mark).
however, if change commands have >nul: 2>nul:
on end, download goes through without issue, suspect it's issue way wget
writes output (without newlines). works if don't use redirection on output , error streams, strengthens assertion.
Comments
Post a Comment