DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Runtime.getruntime.exec(); for my java compiler (http://www.daniweb.com/forums/thread88588.html)

w32.sysfile Sep 5th, 2007 6:43 am
Runtime.getruntime.exec(); for my java compiler
 
i face a problem here..

i am creating a compiler for java, the compilation part is done,and now i have a problem in the running the class compiled..

i use the runtime.getruntime().exec() method to run the class..

and what happen is, for example, i have a simple java file like

public static void main(String[]args)
{
System.out.print("This message");
}
and i run this class

it will show a line in the command prompt "this message",but after that it will closed straigth away, thus, the user has no chance to see the output of the class..

can anyone help me, sorry for my bad english
hope that you all understand
thanks

hidash_in Oct 10th, 2007 1:01 pm
Re: Runtime.getruntime.exec(); for my java compiler
 
can u tell where u r running ur program in command prompt or any other java compilation software.
reply as soon.

Ezzaral Oct 10th, 2007 1:43 pm
Re: Runtime.getruntime.exec(); for my java compiler
 
If you are running in Windows, try prefacing the command with "cmd /c start ";

jwenting Oct 10th, 2007 3:01 pm
Re: Runtime.getruntime.exec(); for my java compiler
 
you are not creating a compiler, you're creating a program that tries to call a compiler someone else created.

The reason your output is not retained is likely because you're launching another process which under Windows means another command shell, which gets closed as soon as that process completes.

And all that when you don't have to create another process at all, but can run any public method in any Java class from any method in any other Java class as long as the class you want to access is on the classpath.

lookof2day Oct 11th, 2007 1:32 pm
Re: Runtime.getruntime.exec(); for my java compiler
 
Well in that case I simply add a readline statement after the print statement. So unless and until you don't press a key it won't exit.


All times are GMT -4. The time now is 12:00 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC