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!

I Didnt Know you could do that in JAVA?! 2

Status
Not open for further replies.

Nandito

Programmer
Apr 12, 2000
31
0
0
AU
Visit site
Yes...... Today in my Java lecture, I was figuring out with one of my collegues how we could start netscape from a Java application. And well it worked...Not only where we able to load Netscape..but also I tried with oddly enough powerpoint!..<br>&nbsp;private void openHelp()<br>&nbsp;{ try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process process = Runtime.getRuntime().exec(&quot;helpc.bat&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;catch (Exception e)<br>&nbsp;&nbsp;&nbsp;{ System.out.println(&quot;Does not exits..make sure help.html does exist&quot;);<br>&nbsp;&nbsp;}<br>}<br>Thats the piece of code that starts powerpoint.<br>However I figure out that the Process object only executes files that are executible.&nbsp;&nbsp;From the command line you can put whatever.ppt and the powerpoint would fire up.&nbsp;&nbsp;But whatever.ppt is not an executible, so i though it would be better to put whatever.ppt in a batch file (Since batch files are executible) and it does.<br><br>However....as we all know..a program written on a dependant on anotherone is not good for portability issues.&nbsp;&nbsp;However...it does save time! if you wanted to display html or other information (eg .doc files)<br>
 
Hi!<br><br>If I understand you well:<br><br>This code try to run the specified file with the OS, and the OS will start the associated<br>application with this file. I tried it on NT, but if you use WinXXXX, change the cmd to command.<br><br>import java.io.*;<br>import java.util.*;<br><br>public class ShellExecute {<br>public static void main(String[] args) {<br>if (args.length!=1) {<br>System.out.println(&quot;Usage: ShellExecute FileName&quot;);<br>System.exit(0);<br>}<br>try {<br>Runtime.getRuntime().exec(&quot;cmd /c &quot;+args[0]); <br>} catch (Throwable t) { t.printStackTrace(); }<br>}<br>}<br><br>Bye, Otto.
 
Otto.. Do you think is good programming practice? ie making programs that use other applications.&nbsp;&nbsp;Although this concept is similar to&nbsp;&nbsp;Microsoft integration of their office software. But Java...is more platform independant, probably if we let users a choice on what OS they have and thus run the according program.<br><br>By the way, are there any command lines from the command shell for powerpoint? ie display in presentation view only?<br>
 
Hi!<br><br>You are right. It is not a good programming practice. Only a (working) solution to WinXXXX (and unix; change the cmd to /bin/sh...) platforms. BTW, is the powerpoint runnable on other OS(s)?<br>Sorry, but I do not know powerpoint.<br><br>Bye, Otto.<br>
 
Hi ALL,<br>&nbsp;&nbsp;&nbsp;Is it possible to use this way ..<br><br>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>I want to use runtime exec to run a.class from b as if we do in cmd prompt.<br>--------------------------------<br>class a{<br>&nbsp;public static void main(String args[]){<br>&nbsp;&nbsp;&nbsp;System.out.println(&quot; hai .. it works&quot;);<br>&nbsp;}<br>}<br><br><br>class b{<br>&nbsp;public static void main(String args[]){<br><br>&nbsp;&nbsp;&nbsp;//here the path to java & the a.class is given seperated by a comma.<br>&nbsp;&nbsp;&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;&nbsp;&nbsp;System.out.println(&quot;after calling exec&quot;);<br>&nbsp;}<br>}<br><br>-------------------------<br>if u run this class b .. it gives out <br><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<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top