On Wed, 4 Aug 1999, Susan Moffat wrote:

> Hi
>
> I'm trying to perform unix commands from my Java program and have
> tried using the Runtime class as follows:
>
>     Process proc = Runtime.getRuntime().exec("/bin/sh -c \"ls;pwd\"");
>
> to try to perform more than one command in the same runtime
> instance.  Apparently calling exec again will result in a new
> process being ran and as I'm trying to perform the commands using
> the same instance (I'll actually be trying to use the "su" command
> and perform several commands whilst as the superuser).
>
> I've also tried writing to the returned Process class's output
> stream by using a BufferedWriter taking an OutputStreamWriter from
> the Process.getOutputStream() method - to no avail. As when I
> perform the flush() on the writer, an IOException occurs with a
> write error thrown in the FileOutputStream.write() method, which
> flush() inherits from.
>
> Has anyone managed to perform operating system commands from within
> their Java code?

Did you try it without the ";", i.e. with just a single command?  I
have a feeling that might be the problem.

If that does work, maybe you could put your series of commands in a
script, and exec that.  Or perhaps you could try using csh instead of
sh and use csh's "()" construct (you can put multiple ";" separated
commands in the parentheses.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to