Discuss Why doesn't start another process? in the Java Help forum on Dev Shed. Why doesn't start another process? Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
Time spent in forums: 1 Day 17 h 10 m 20 sec
Reputation Power: 14
Your code may well be printing the message more than once, but the exec-ed call will be running in a different thread that will not have access to the console that outputs the first message; they will be totally separate processes.
Note though that it is not just going to print the message out twice, it is going to keep running and running, because each call spawns a new process. I am going to reboot my PC now to kill off the dozens of threads that are taking up 100% of my CPU
Time spent in forums: 1 Month 1 Week 2 h 43 m 16 sec
Reputation Power: 1312
Originally Posted by marlonmin
I think this code should print the message more than once, but it only prints once. What's the problem? Thanks.
Your subprocess is piping its output back to the main process. It isn't printed automatically; you have to do it yourself. Here's an example. For obvious reasons, I didn't retain your infinite-respawn cycle. You may need to change the exec() command string to something appropriate for your system if you're not on Linux. (Anything that generates output without reading input will do.)