Forums Register Login

Calling an exe from java

+Pie Number of slices to send: Send
I'm writing an application that need to call a PowerBuilder executable.
How can I do this?
+Pie Number of slices to send: Send
Hi,
Yes from a standalone java program you should be able to do this through use of the java.lang.Runtime object exec method. Look it up in the api and play around with it. I've used it successfully to run dos commands. If the command to launch powberbuilder app is complex, but it in a bat file and execute the bat file. If you can't figure the api out, let me know and try to dig up a code sample.
+Pie Number of slices to send: Send
Hi Mary,
I dug up a code sample:
String command = "c:\\acodetest\\mybat.bat";
Process process = null;
int exitVal = -10;
try {
process = Runtime.getRuntime().exec(command);
process.waitFor();
exitVal = process.exitValue();
} catch (InterruptedException ie) {
System.out.println(ie.getMessage());
} catch (java.io.IOException ioe) {
System.out.println(ioe.getMessage());
}
System.out.println("Ran mybat - return value was " + exitVal);
the bat file contents are:
cd c:\acodetest
dir > a.out
You'll know if it works, because a file, a.out will be produced. (make sure c:\acodetest is where the bat file is - or change the sample code.)
Hope this helps.
- Lu Battist
+Pie Number of slices to send: Send
Hi Lu,
Thanks for your answer. It's veru helpful.
Can I use the same procedure to run the executable from a java web application, having the executable sitting on the server?
My application is a JSP / Servlets solution.
Thanks
Mary.
+Pie Number of slices to send: Send
Hi Mary,
Yes you can do this from a JSP/Servlet but you do need to set up a security policy to allow for it. I've done this before but don't remember the specifics. J2EE or JDK doc should cover it.
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1149 times.
Similar Threads
Calling executable from an action class
calling java servlet from Powerbuilder
Power builder to j2ee converted sample application
Creating Java DLL's
How to Hide Java Console
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:53:42.