Forums Register Login

another question about exec() to open a cmd window

+Pie Number of slices to send: Send
for example:I use Runtime.getRuntime().exec("cmd /k dir"); the result is it run in the background. but i want to it show me the cmd window. how to do that? any help will be appreciated.
+Pie Number of slices to send: Send
I may be trying to do the same thing this week. It would be nice to get a response before then. This is another new thing for me. I have code to start a second application from the first, but haven't tried to start a command window for it.

I have little experience - but perhaps this will help. I think that the arguments might need to be in a String array.

Use a second argument if you need to set environmnet variables.
[ August 28, 2007: Message edited by: Roger F. Gay ]
+Pie Number of slices to send: Send
 

Originally posted by Roger F. Gay:
I may be trying to do the same thing this week. It would be nice to get a response before then. This is another new thing for me. I have code to start a second application from the first, but haven't tried to start a command window for it.

I have little experience - but perhaps this will help. I think that the arguments might need to be in a String array.

Use a second argument if you need to set environmnet variables.

[ August 28, 2007: Message edited by: Roger F. Gay ]



i don't understand what is the "environmnet variables"?
i've try it but i also can not get a cmd window.......so if i use exec to run a java program, i can not get the console information......so the point.....so i must get a cmd window by using runTime.exec("java -cp test doTest.test")
+Pie Number of slices to send: Send
Environment variables are things like path and classpath, that are set for the whole system. You can view or edit them through the Advanced tab in Systems on the Control Panel - which you bring up by clicking start and selecting Control Panel (in Windows). Control-Panel->System->Advanced-tab->Environment-variables-button

I don't understand how starting a Java program brings up a cmd window if you don't know how to bring up a cmd window from a Java program? How does doTest.test (.class?) bring up a cmd window?
+Pie Number of slices to send: Send
If you want to use one string for the command (with arguments), rather than a command array, try ProcessBuilder.
[ August 28, 2007: Message edited by: Roger F. Gay ]
+Pie Number of slices to send: Send
 

Originally posted by Roger F. Gay:
Environment variables are things like path and classpath, that are set for the whole system. You can view or edit them through the Advanced tab in Systems on the Control Panel - which you bring up by clicking start and selecting Control Panel (in Windows). Control-Panel->System->Advanced-tab->Environment-variables-button

I don't understand how starting a Java program brings up a cmd window if you don't know how to bring up a cmd window from a Java program? How does doTest.test (.class?) bring up a cmd window?



that means i get two programs(p1,p2) to invoke each other. at first p1 run and when the condition is right p1 invoke the p2 before quit.but in this action, the p2 is running in background you can see the "cmd.exe,java.exe" in process explore but can not get another cmd window. and when some condtions is right p2 also invoke the p1 before quit. the situtation is the same as before. but i need the cmd window to see some System.out.print information. because our main program(whatever p1,p2) print the information to the cmd window. So i need cmd window......
+Pie Number of slices to send: Send
i found a method but i think this is not the best way to open the cmd window. that is using the .bat file. with .bat file in java program it can pop-up the cmd window...
+Pie Number of slices to send: Send
Hey guys i get the method to open another window(or explore) by using cmd "start"
String startCmd="cmd /k start D:\\";
p2=Runtime.getRuntime().exec(startCmd);
try it...it can also anyother window.....
but you'd better not write the "process.destory()"
[ August 28, 2007: Message edited by: lei feng ]
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2041 times.
Similar Threads
Cannot see exec()'ed app
Runtime.getRuntime().exec() problem
problem in running dos command from java
launching an application from swing button
tool / code to open IE window from Java app
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:05:08.