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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems running an exe from Java App

Status
Not open for further replies.
Jun 19, 2001
86
US
Here's a weird one. I am running a program called Pad.exe from my Application. Pad.exe is a simple DOS app that pads each line in a file with a specified length. the following is the line from my Java App:

Process p = Runtime.getRuntime().exec(p_program + " 749 " + i_directory + "\\" + txtfile + " " + o_directory + "\\" + txtfile);

p_program is Pad.exe
749 is the pad length
i_directory is the input directory
o_directory is the output directory
txtfile is the file to be padded

Here is where it gets weird. If I run my Java Application I get a windows pop-up box with the following error:

C:\WINDOWS\system32\ntvdm.exe.
Error while setting up enviroment for the application. Choose 'Close' to terminate application.

After I close the error window I can go to the command line and run the Pad.exe program at the DOS prompt. After I run Pad.exe at the DOS prompt I can run my Java Application from the the same command line and it runs successfully. It is almost like when I manually run Pad.exe from the comand line it is setting up the enviroment. I don't see any changes to the enviroment variables. Can anyone think of something I can do in my Java App to get the environment setup.

Nathan
 
Try something more like this and see if it works. Also build the string as a variable so you can output it using System.out.println( str) to see exactly what your string concatenation code is building.
Code:
cmd /c start pad.exe <the params for pad>

-pete
 
Try to put your command and parameters in a String array, like the following example.
The following code will launch notepad on a Windows system.

public class WinCmdExample {

public WinCmdExample() {
}

private void doIt() {
Runtime run = Runtime.getRuntime();
//String[] args = { &quot;COMMAND.COM&quot;, &quot;/C&quot;, &quot;notepad&quot; };
String[] args = { &quot;notepad&quot;, &quot;D:\\Test.txt&quot; };
try {
run.exec(args);
} catch (java.io.IOException e) {
}
}

public static void main(String[] args) {
WinCmdExample example = new WinCmdExample();
example.doIt();
}
}
 
Ended up using:

cmd /c start pad.exe <the params for pad>

Thanks for the help.

Nathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top