From owner-freebsd-questions Fri Dec 12 11:11:23 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id LAA15366 for questions-outgoing; Fri, 12 Dec 1997 11:11:23 -0800 (PST) (envelope-from owner-freebsd-questions) Received: from cs.iastate.edu (root@cs.iastate.edu [129.186.3.1]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id LAA15351 for ; Fri, 12 Dec 1997 11:11:14 -0800 (PST) (envelope-from ghelmer@cs.iastate.edu) Received: from popeye.cs.iastate.edu (popeye.cs.iastate.edu [129.186.3.4]) by cs.iastate.edu (8.8.7/8.8.7) with ESMTP id NAA00596; Fri, 12 Dec 1997 13:11:01 -0600 (CST) Received: from localhost (ghelmer@localhost) by popeye.cs.iastate.edu (8.8.7/8.7.1) with SMTP id NAA16072; Fri, 12 Dec 1997 13:11:00 -0600 (CST) X-Authentication-Warning: popeye.cs.iastate.edu: ghelmer owned process doing -bs Date: Fri, 12 Dec 1997 13:10:59 -0600 (CST) From: Guy Helmer To: Valter Mazzaro cc: freebsd-questions@FreeBSD.ORG Subject: Re: java should execute scripts In-Reply-To: <199712121734.SAA06798@kk660.kk.etx.ericsson.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Fri, 12 Dec 1997, Valter Mazzaro wrote: > I wonder how it's possible to run unix scripts from java. > I know that I can run an executable file by running rt.exec command, > for example rt.exec("dhcpconf le0 release"), but if I create a script, > let's say stopDHCP that contains just the line:dhcpconf le0 release > the command rt.exec("stopDHCP") doesn't work. > Any hint? >From the Java Programmers FAQ at http://www.netmeg.net/faq/computers/programming/languages/java/programmers-faq/ Question 10.5: How do I execute a command from Java? A. Use Runtime.getRuntime.exec( myCommandString ) Where myCommandString is something like "/full/pathname/command" I understand that the full pathname may be required (it seems like I've read that rt.exec() doesn't use the path, but that may be incorrect). At any rate, if you don't wish to use the full pathname, try using rt.exec("./stopDHCP") as "." may not be in your PATH. With your shell script, be sure the first line is "#!/bin/sh" and the file is executable (as in "chmod +x stopDHCP"). Otherwise you may need to prefix the command to run your script with "/bin/sh", like rt.exec("/bin/sh stopDHCP"). Hope this helps, Guy Helmer Guy Helmer, Computer Science Graduate Student - ghelmer@cs.iastate.edu Iowa State University http://www.cs.iastate.edu/~ghelmer Research Assistant, Scalable Computing Laboratory, Ames Laboratory