Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi ALL, Is it possible to use this way .. source files : a.ja

Status
Not open for further replies.

ganeshkondal

Programmer
May 2, 2000
5
0
0
US
Visit site
Hi ALL,<br>&nbsp;&nbsp;&nbsp;&nbsp;Is it possible to use this way ..<br><br>&nbsp;source files : a.java,b.java.<br>a.java&nbsp;&nbsp;- &gt; compiled in the same dir (let it be c:\javaHome\a.class)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I want to use runtime exec to run a.class from b as if we do in cmd prompt.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--------------------------------<br>class a{<br>&nbsp;public static void main(String args[]){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot; hai .. it works&quot;);<br>&nbsp;}<br>}<br>--------------<br>class b{<br>&nbsp;public static void main(String args[]){<br>&nbsp;&nbsp;//here the path to java & the a.class is&nbsp;&nbsp;&nbsp;//given seperated by a comma.<br>&nbsp;&nbsp;System.out.println(&quot;b4 calling exec&quot;);<br>&nbsp;&nbsp;..= Runtime.getRuntime().exec(&quot;java &quot;,&quot;a&quot;);&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;System.out.println(&quot;after calling exec&quot;);<br>&nbsp;&nbsp;}<br>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-------------------------<br>if u run this class b .. it gives out <br>b4 calling exec and after calling exec ..<br><br>i expected &quot;hai ..it works &quot; to come out inbtw .<br><br>help me out.<br><br>regards,<br>ganesh
 
In your a.java, have it wait for a keypress.&nbsp;&nbsp;I suspect it's opening it's own console window, and closing it as soon as a.class finishes, so you're not seeing it.<br><br>Chip H.<br>
 
Hi Chip,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have tried a few things like this ..<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putting a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;system.in.read()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- opening a text file and writing a string in it..<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in both of the cases it s not showing me signs of going in.<br><br>Its not waiting for my key press or its opening a text file .<br><br>I also tried using&nbsp;&nbsp;&nbsp;exec(String[])<br><br>stringarray - contains the&nbsp;&nbsp;&quot; java &quot; and &quot; classfile a &quot;<br><br>&nbsp;-- Process&nbsp;&nbsp;p = Runtime.getRuntime().exec(stringarray);<br><br>I dont know why&nbsp;&nbsp;the class a is not running . - ( starting a new process)<br><br>Help me out. <br><br>thanx,<br>ganesh<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
It may not be running cuz the class file in itself with java are not executible..<br>what you may try is<br>Process&nbsp;&nbsp;p = Runtime.getRuntime().exec(runme.bat)<br><br>Where runme.bat would contain the<br>java classfile<br><br>Try it like this :D<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top