jason101799
asked on
Program error!!
<%@ page import="java.io.*";%>
<%!
public void display(){
String rtn="";
Runtime rt = Runtime.getRuntime();
try {
Process d = rt.exec("ls");
InputStream in = d.getInputStream();
DataInputStream din = new DataInputStream(in);
String inline = new String("start");
while (inline != null) {
inline = din.readLine();
if (inline != null ) {
rtn = inline;
System.out.println(rtn);
}
}
din.close();
}
catch(IOException e) {
System.out.println("IOExce ption");
}
//return rtn;
}
%>
<html><head><title>test</t itle></hea d><body>
<%= display()%>
</body></html>
__________________________ __________ __________ __________ __
Whats worng with the above code? How can I print out all the lines when I execute the ls command? How do I change directory from the above code?
Please help.
Cheers
Jason
<%!
public void display(){
String rtn="";
Runtime rt = Runtime.getRuntime();
try {
Process d = rt.exec("ls");
InputStream in = d.getInputStream();
DataInputStream din = new DataInputStream(in);
String inline = new String("start");
while (inline != null) {
inline = din.readLine();
if (inline != null ) {
rtn = inline;
System.out.println(rtn);
}
}
din.close();
}
catch(IOException e) {
System.out.println("IOExce
}
//return rtn;
}
%>
<html><head><title>test</t
<%= display()%>
</body></html>
__________________________
Whats worng with the above code? How can I print out all the lines when I execute the ls command? How do I change directory from the above code?
Please help.
Cheers
Jason
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ovi,
I wanted it to be in JSP. Can u help? One more qs is how do i execute a file which contains a string like "echo hello".
CHeers
Jason
I wanted it to be in JSP. Can u help? One more qs is how do i execute a file which contains a string like "echo hello".
CHeers
Jason
ASKER
ovi,
I need that file to be in JSP, perhaps you can advice.
Thanks
Cheers
Jason
I need that file to be in JSP, perhaps you can advice.
Thanks
Cheers
Jason
jason@lc,
These questions are still open. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=win2k&qid=20167319
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20153401
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20151128
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20146743
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20150594
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20245522
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20239352
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20166221
https://www.experts-exchange.com/jsp/qShow.jsp?ta=xml&qid=20243323
https://www.experts-exchange.com/jsp/qShow.jsp?ta=exchangesvr&qid=20240796
EXPERTS: Please leave your thoughts on this question here.
Thanks,
Netminder
Community Support Moderator
Experts Exchange
These questions are still open. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=win2k&qid=20167319
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20153401
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20151128
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20146743
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20150594
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20245522
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20239352
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20166221
https://www.experts-exchange.com/jsp/qShow.jsp?ta=xml&qid=20243323
https://www.experts-exchange.com/jsp/qShow.jsp?ta=exchangesvr&qid=20240796
EXPERTS: Please leave your thoughts on this question here.
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Admin notified of User neglect. Force-accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
public class OutputCapture {
public static void main(String[] args) {
String cmd = "ls -al";
try {
Process process = Runtime.getRuntime().exec(
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println("Line : " + line);
}
} catch(Exception e) {}
}
}