From: Glen S. <gl...@en...> - 2001-07-10 13:29:11
|
On Tue, 10 Jul 2001, Kevin McNamee wrote: > Is there no possibility to run arbitrary system commands without writing > Java code? In a nutshell, no... however, it is not Java code you will be writing... it will be Jython :-) For example: from java.lang import * Process p = Runtime.getRuntime().exec("ls -al") p.waitFor() |
From: Kevin M. <qk...@lm...> - 2001-07-11 08:11:48
|
The solution is a bit more complicated it seems. The following works well. from java.io import * from java.lang import * proc = Runtime.getRuntime().exec("ls -la") stdin = proc.getInputStream() isr = InputStreamReader(stdin) br=BufferedReader(isr) line = br.readLine() while line != None : print(line) line = br.readLine() I got some help from this resource: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html Comments? On Tue, 10 Jul 2001, D-Man wrote: > On Tue, Jul 10, 2001 at 03:44:54PM +0200, Kevin McNamee wrote: > | OK, this works, but it just returns '0'. I guess this the return code from > | the 'ls -al' command. Where is the actual output? > > Yep. That means that the command completed successfully (at least > that's the convention on *nix). > > See > http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Process.html. > java.lang.Runtime.exec returns a java.lang.Process object to you. > That Process object has methods > > getOutputStream() > getInputStream() > getErrorStream() > exitValue() > > You are looking to getOutputStream from the Process. The waitFor > method returns the exitValue. > > HTH, > -D > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users > _________________________________________________ Name/Title : Kevin McNamee, Software Consultant Phone : +46 13 32 1165 E-Mail : kev...@er... |
From: D-Man <ds...@ri...> - 2001-07-10 13:38:21
|
On Tue, Jul 10, 2001 at 06:20:27AM -0700, Glen Starchman wrote: | On Tue, 10 Jul 2001, Kevin McNamee wrote: | > Is there no possibility to run arbitrary system commands without writing | > Java code? | | | In a nutshell, no... however, it is not Java code you will be | writing... it will be Jython :-) | | For example: | | from java.lang import * | Process p = Runtime.getRuntime().exec("ls -al") ^^^^^^^ :-) That is Java. Jython doesn't use type declarations. | p.waitFor() -D |
From: Kevin M. <qk...@lm...> - 2001-07-10 13:45:00
|
OK, this works, but it just returns '0'. I guess this the return code from the 'ls -al' command. Where is the actual output? On Tue, 10 Jul 2001, D-Man wrote: > On Tue, Jul 10, 2001 at 06:20:27AM -0700, Glen Starchman wrote: > | On Tue, 10 Jul 2001, Kevin McNamee wrote: > | > Is there no possibility to run arbitrary system commands without writing > | > Java code? > | > | > | In a nutshell, no... however, it is not Java code you will be > | writing... it will be Jython :-) > | > | For example: > | > | from java.lang import * > | Process p = Runtime.getRuntime().exec("ls -al") > ^^^^^^^ > > :-) That is Java. Jython doesn't use type declarations. > > | p.waitFor() > > -D > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users > _________________________________________________ Name/Title : Kevin McNamee, Software Consultant Phone : +46 13 32 1165 E-Mail : kev...@er... |
From: D-Man <ds...@ri...> - 2001-07-10 15:32:04
|
On Tue, Jul 10, 2001 at 03:44:54PM +0200, Kevin McNamee wrote: | OK, this works, but it just returns '0'. I guess this the return code from | the 'ls -al' command. Where is the actual output? Yep. That means that the command completed successfully (at least that's the convention on *nix). See http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Process.html. java.lang.Runtime.exec returns a java.lang.Process object to you. That Process object has methods getOutputStream() getInputStream() getErrorStream() exitValue() You are looking to getOutputStream from the Process. The waitFor method returns the exitValue. HTH, -D |
From: Glen S. <gl...@en...> - 2001-07-10 14:14:02
|
On Tue, 10 Jul 2001, D-Man wrote: > On Tue, Jul 10, 2001 at 06:20:27AM -0700, Glen Starchman wrote: > | On Tue, 10 Jul 2001, Kevin McNamee wrote: > | > Is there no possibility to run arbitrary system commands without writing > | > Java code? > | > | > | In a nutshell, no... however, it is not Java code you will be > | writing... it will be Jython :-) > | > | For example: > | > | from java.lang import * > | Process p = Runtime.getRuntime().exec("ls -al") > ^^^^^^^ > > :-) That is Java. Jython doesn't use type declarations. My bad... I guess since I am mixing Java classes and Python classes together so much I tend to get confused from time to time. > > | p.waitFor() > > -D > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users -- So what can we do? There is only one solution. Start killing. If you know someone who is excited about compileable ASP code... KILL THEM. If you know someone who has Visual Studio .NET beta... KILL THEIR WHOLE FAMILY. -- /. posting |