File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Newbie! Launch Program from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie! Launch Program from Java" Watch "Newbie! Launch Program from Java" New topic
Author

Newbie! Launch Program from Java

Scott Frye
Greenhorn

Joined: Dec 15, 2004
Posts: 4
As a final result, I want to be able to launch a perl program (portaltest.pl), hand it 6 arguments and return a URL. However, for starters, I'm trying to open notepad. We are doing this in Vignettes portal. So far, I have imported java.io.* and java.lang.Runtime.*. My command is Runtime.getRuntime().exec("C:\\WINNT\\notepad.exe"); The page renders just fine, but what I am expecting is to have notepad pop up. This is not working. I do not see any errors anywhere. Can someone help.

Thanks

Scott
Scott Frye
Greenhorn

Joined: Dec 15, 2004
Posts: 4
I ran across some code that should open notepad, but all it does is hang. For some reason notepad just doesn't seem to want to open.

Please help!

String cmdline = "C:\\WINNT\\notepad.exe";
// Start the child process.
Runtime myRun = Runtime.getRuntime();
Process p = null;
try{
p = myRun.exec(cmdline);
}
catch(IOException ioe){
out.println("Exec failed: " + ioe);
}
out.println(p);
try{
p.waitFor();
int completeStatus = p.exitValue();
}
catch(InterruptedException ie){
out.println("Exec Interrupted: " + ie);
}
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What kind of program are you writing? And how are you launching your Java program? If this is an applet, the errors will appear in the Java console. If you are running Windows, you can open this console by double-clicking the Java icon in your system tray (by the clock in the lower left corner). If you are running Windows XP or later, you may need to click on the << button to get to icons that aren't used regularly.

Layne


Java API Documentation
The Java Tutorial
Scott Frye
Greenhorn

Joined: Dec 15, 2004
Posts: 4
We are working in the Vignette Portal. We have developed a *.pdb file that uses a view.jsp file. Here is my code... For some reason, it just won't open notepad.

<%@ page
import="com.epicentric.portalbeans.*, com.epicentric.metastore.*, java.io.*, java.lang.Runtime.*"
contentType="text/html; charset=UTF-8"
%>

<%@taglib uri="module-tags" prefix="mod" %>
<mod:view class="com.epicentric.portalbeans.beans.jspbean.JSPView">

<%
//Runtime.getRuntime().exec("C:\\WINNT\\notepad.exe");

String cmdline = "C:\\WINNT\\notepad.exe";
// Start the child process.
Runtime myRun = Runtime.getRuntime();
Process p = null;
try{
p = myRun.exec(cmdline);
}
catch(IOException ioe){
out.println("Exec failed: " + ioe);
}
//out.println("Exit value:"+p.waitFor());
//out.println(p);
//try{
// p.waitFor();
// int completeStatus = p.exitValue();
//}
//catch(InterruptedException ie){
// out.println("Exec Interrupted: " + ie);
//}

PortalBean bn = view.getBean();
MetaStoreFolder folder = view.getFolder();
String newwindow = folder.getProperty("newwindow");
String anchorTarget = (newwindow.equals("on")) ? "_blank": "_top";
String redirectURL = (newwindow.equals("on")) ? bn.getProperty("URL") : view.getBean().getFullViewURL("chartmaxx_view");

%>
<a href=<%=redirectURL%> target=<%=anchorTarget%>>ChartMaxx Single Sign-On </a>
</mod:view>
Scott Frye
Greenhorn

Joined: Dec 15, 2004
Posts: 4
Also, I have done a out.println(p); and I get java.lang.Win32Process@2f3276. Any ideas what this means?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Scott Frye:
Also, I have done a out.println(p); and I get java.lang.Win32Process@2f3276. Any ideas what this means?

println() calls the toString() method on the object that is passed as the argument. If a particular class does not override toString(), then the default implementation in Object is called. This default implementation simply prints the concrete type of the object (in this case java.lang.Win32Process), an "@" symbol, and then a hexadecimal representation of the object's hashcode. These details are spelled out in the Java API docs, if you start with System.out and follow the links to the related methods and classes. As you continue programming Java, it will be a great asset to learn how to navigate the API javadocs to find such information.

Keep Coding!

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie! Launch Program from Java