• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using wget from java code to download files

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am trying to implement a program which, among other things, will have to download automatically a number of pdf files I have found using Google. Instead of building something from scratch, I assumed that I could invoke the Linux wget:

String commandString="wget http://www.google.com";
try {

Process process = Runtime.getRuntime().exec(commandString);


} catch (IOException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}


The problem is that I get nothing in the program's folder. Null. Void! i tried also to play a bit with wget's parameters, such as masking the user agent (-U mozilla), setting download limit, etc but still I get nothing downloaded. The command works perfectly from the shell, by the way.
Do you have any ideas what I am doing wrong?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
The first thing I'd try is to read in the output stream from the process.
 
Konstantinos Vasileiou
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I figured it out and it may be useful for other newbies as well:
First, read the great tutorial on the Use of Runtime.exec() before playing with it... My final code looks somewhat like the one in the tutorial (I print only the error stream, as the output stream of wget does not *seem* to give anything useful as info - so there is no need for a second thread.)

The problem was, as the 2nd page of the article indicates: "...failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock."
 
reply
    Bookmark Topic Watch Topic
  • New Topic