Date: Fri, 12 Dec 1997 13:10:59 -0600 (CST) From: Guy Helmer <ghelmer@cs.iastate.edu> To: Valter Mazzaro <teima@kk.etx.ericsson.se> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: java should execute scripts Message-ID: <Pine.HPP.3.96.971212130203.19922H-100000@popeye.cs.iastate.edu> In-Reply-To: <199712121734.SAA06798@kk660.kk.etx.ericsson.se>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.HPP.3.96.971212130203.19922H-100000>