This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Runtime.exec() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime.exec()" Watch "Runtime.exec()" New topic
Author

Runtime.exec()

trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
in the java program can we give like this
Runtime r=Runtime.getRuntime();
Process p=r.exec("java param1 param2");
please tellme .iam trying to execute .but no output is comming
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3602
    
  15
The output from the program can be read by calling the Process.getInputStream() and Process.getErrorStream() methods. See the Process class API docs for more details.

Also read this article


Joanne
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
my task is
Runtime r=Runtime.getRuntime();
Process p=r.exec("java -Dweblogic.Domain=mydomain weblogic.Server")
when i execute this program weblogicserver should start with specified domainname
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3602
    
  15
I'd be very surprised if that command line did anything. You need to tell java what program to run. All you are doing is passing it an environment variable.

Try reading the input and error streams and see what messages are being output.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

Originally posted by Joanne Neal:
I'd be very surprised if that command line did anything. You need to tell java what program to run. All you are doing is passing it an environment variable.

No he's not, look again at his command line:

java -Dweblogic.Domain=mydomain weblogic.Server

weblogic.Server is the package and classname of the class he's trying to run.
[ October 25, 2005: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
i have the situation like this
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd /c start d:/bea/weblogic700/server/bin/setWLSEnv.cmd")
now it is working.what i have to do is for this setWLSEnv.cmd i have tpass parameters java -Dweblogic.Doamin=mydomain -Dweblogic.Name =servername weblogic.Server.when i gave this command weblogicserver should start automatically with specified domainname and servername.can we passlike this below
String s= -Dweblogic.Domain=mydomain -Dweblogic.Name=myserver
Process p=r.exec("cmd /c start d:/bea/weblogic700/server/bin/setWLSEnv.cmd j java s");
when i gave this command weblogicserver should start automatically with the specified domainname and servername.please tellme how to do this
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3602
    
  15
Thanks Jesper. I must get my eyes tested. I was sure there was a dot and not a space between mydomain and weblogic.Server

trinadh - try

or, even better, take a look at the version of exec that takes an array of Strings as an argument. It makes the code a lot easier to read when you have a long command line.
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
Process p=r.exec("cmd /c start d:/bea/weblogic700/server/bin/setWLSEnv.cmd java "+s);
i have tried like this also.
no output is comming
when iam trying to use streams here
InputStream is=p.getInputStream();
it is not writing any data to the stream
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
In my opinion, you should write a batch file or a shell script (depending on the operating system) that does this. You should use the correct tool for the job, and in my opinion, Java isn't the correct tool in this case.

Layne


Java API Documentation
The Java Tutorial
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
This means that we cannot open weblogicserver from java program by specifying our domainname,servername,portnumber etc
 
GeeCON Prague 2014
 
subject: Runtime.exec()