Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie! Launch Program from Java

 
Scott Frye
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Scott Frye
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I have done a out.println(p); and I get java.lang.Win32Process@2f3276. Any ideas what this means?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic