how to call linux command with java ?
hi list, I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet. Please, I need some help here. Thx a lot ===== Linux Aremania __________________________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo http://search.yahoo.com
On Mittwoch, 16. April 2003 15:30, Linux Aremania wrote:
I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet.
I don't program Java, but from what I know you have only very limited access
to the client system in Java applets - that would be a considerable security
hole. Imagine everybody who can set up a web server could run commands
remotely on your machine over the Internet! (That would be the consequence of
what you wish to do).
Bottom line: I doubt you can do that at all in a Java applet.
Any true expert's opinion?
CU
--
Stefan Hundhammer
On Wednesday 16 April 2003 15:37, Stefan Hundhammer wrote:
On Mittwoch, 16. April 2003 15:30, Linux Aremania wrote:
I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet.
I don't program Java, but from what I know you have only very limited access to the client system in Java applets - that would be a considerable security hole. Imagine everybody who can set up a web server could run commands remotely on your machine over the Internet! (That would be the consequence of what you wish to do).
Bottom line: I doubt you can do that at all in a Java applet.
Any true expert's opinion?
Oh, you're probably right about that. Exec class might not work in an -applet-. -- tinus ___________________________________________________ "Words are weightless here on earth Because they're free." -- Josh Homme
On Mittwoch, 16. April 2003 15:30, Linux Aremania wrote:
I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet.
Never tried this myself, but perhaps "signed-applet" and/or "security policy" is what you're looking for? Try looking at Java tutorial at java.sun.com. As for invoking OS's command, check documentation of class java.lang.RunTime. -- -- Verdi March --
On Mittwoch, 16. April 2003 15:30, Linux Aremania wrote:
I wanna display the output of "ps -ax" command in applet.
P.S.: If you have access to the file system in that applet (which I doubt) you
could try accessing the /proc file system to emulate that "ps" call.
CU
--
Stefan Hundhammer
On Wednesday 16 April 2003 15:30, Linux Aremania wrote:
hi list, I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet.
You are probably looking for something like this: http://mindprod.com/jglossexec.html (windows-based, but works for Linux as well, I think). I don't really think it's a great idea to pass system-commands from within a system-independant language like java, but hey, it works. -- tinus ___________________________________________________ "Words are weightless here on earth Because they're free." -- Josh Homme
On Wed, 2003-04-16 at 15:30, Linux Aremania wrote:
hi list, I wanna make java application which call linux command, but I don't know how to call linux command. For example : I wanna display the output of "ps -ax" command in applet.
You can only do this in a trusted environment. If you're working in a corporate intranet or similar you need to set the clients to trust applets signed by you. Look at the documentation for java's security manager. A google search turns up many hits. Here's one http://www.securingjava.com/chapter-two/chapter-two-8.html
Linux Aremania wrote : | I wanna make java application which call linux | command, but I don't know how to call linux command. | For example : I wanna display the output of "ps -ax" | command in applet. | you can't do that from an applet, protected !!, what you can do is write a java program that does this. But your browser won't allow you to execute external commands from an applet in a java program, this class can help you : // // (C) Dries Pruimboom (dries@irssystems.nl) // Use at own risk !! // Might not be fit for your use, you decide !! // // // Executer class for simple execution of external programs // // General usage : // // Executer exe = new Executer("find /"); // String line; // // while ((line = exe.ReadLine())!=null) // { // System.out.println(line); // } // class Executer { Process proc; BufferedReader input; BufferedWriter output; public int ExitVal; // // str contains the command to execute // Executer(String str) { try { Runtime runtime = Runtime.getRuntime(); proc = runtime.exec(str); input = new BufferedReader(new InputStreamReader(proc.getInputStream())); output = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())); } catch (Exception e) { System.out.println(e); } } // // Read a line of output from external program // public String ReadLine() { String hlp=null; try { hlp = input.readLine(); } catch (Exception e) { hlp=null; } return (hlp); } // // Write line of data to external program // public void WriteLine(String str) { try { output.write(str); output.flush(); } catch (Exception e) { } } public boolean DataAvail() { boolean res=false; try { res = input.ready(); } catch (IOException e) { } return(res); } // // Do a more or less nice end of this process // this is not actually needed!. // public void EndProcess() { try { input.close(); output.close(); } catch (Exception e) { } } public boolean Stopped() { boolean res = false; if (!DataAvail()) { try { ExitVal = proc.exitValue(); res=true; } catch (IllegalThreadStateException e) { } } return(res); } } Hope this will help you Grtz Dries -- <End of message>
participants (6)
-
Anders Johansson
-
dries
-
Linux Aremania
-
Martijn Houtman
-
Stefan Hundhammer
-
Verdi March