Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-24-2010, 05:42 AM
|
#1
|
Member
Registered: Sep 2008
Posts: 35
Rep:
|
Java code to implement "wget" to save a web page in linux
This is the code i used, there is no error in execution but no file is bein saved in the working directory.
I'm new in java,so just started learning.
if some one can help me out with this wil be really great
Thanx in advance
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
Process q = Runtime.getRuntime().exec("export http_proxy='http://it06106036:it06106036@172.16.0.254:8080'");
Process p = Runtime.getRuntime().exec(" wget -U MyBrowser/1.0 http://59.165.190.44/exams/results1/btechNEW/BT55displayNEW.php?regno=mkageit026&Submit=Submit");
BufferedReader r= new BufferedReader(new InputStreamReader(q.getInputStream())); //juz added this to call the constructors
r.readLine();
BufferedReader s= new BufferedReader(new InputStreamReader(p.getInputStream()));
s.readLine();
}catch(IOException ioe)
{
System.exit(1);
}
}
}
|
|
|
02-24-2010, 03:15 PM
|
#3
|
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012
Rep:
|
The two execs run in completely separate environments.
Anyhow, this is completely the wrong way to go about this. Use an actual HTTP client API, like Apache's. Or *maybe* a JNI'd interface to cURL.
|
|
|
03-06-2010, 01:18 AM
|
#4
|
Member
Registered: Sep 2008
Posts: 35
Original Poster
Rep:
|
in a shell,it works fine and it saves the page in the home directory
Quote:
Originally Posted by smoker
|
|
|
|
03-08-2010, 12:10 AM
|
#5
|
Member
Registered: Sep 2008
Posts: 35
Original Poster
Rep:
|
import java.io.*;
import java.io.IOException;
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
String cmd = "ls -al";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);}
}catch(IOException ioe)
{
System.exit(1);
}
}
}
i tried to just implement ls command....
and during that when i compile i get the following error.I have added try and catch but still iam gettin unhandled exception .plz help
Station71:~/RESA/wget# javac Hel.java
----------
1. ERROR in Hel.java (at line 25)
pr.waitFor();
^^^^^^^^^^^^
Unhandled exception type InterruptedException
----------
|
|
|
03-08-2010, 03:02 AM
|
#6
|
Member
Registered: Sep 2008
Posts: 35
Original Poster
Rep:
|
when i removed pr.waitFor(),it worked just fine.
thank you
Quote:
Originally Posted by Kakarot_Rathish
import java.io.*;
import java.io.IOException;
public class Hel
{
public static void main(String args[])
throws IOException
{
try
{
String cmd = "ls -al";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);}
}catch(IOException ioe)
{
System.exit(1);
}
}
}
i tried to just implement ls command....
and during that when i compile i get the following error.I have added try and catch but still iam gettin unhandled exception .plz help
Station71:~/RESA/wget# javac Hel.java
----------
1. ERROR in Hel.java (at line 25)
pr.waitFor();
^^^^^^^^^^^^
Unhandled exception type InterruptedException
----------
|
|
|
|
All times are GMT -5. The time now is 04:23 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|