Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime.exec()

 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This means that we cannot open weblogicserver from java program by specifying our domainname,servername,portnumber etc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic