Results 1 to 7 of 7
- 02-25-2010, 10:34 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
called external program does not automatically write file
I have this program.exe which, after being called from a command line environment, e.g.:
C:\> program.exe input.inp
automatically writes a file (with a generic name), e.g. "output.out", in the directory I am working in.
However, when I try to call this program.exe from my java code, it does not write the output.out file as it does when using the command line.
my java code looks like:
try {
exe_path="C:/.../";
workDir_path="C:/.../";
Runtime rt = Runtime.getRuntime();
String [] command = {exe_path+"program.exe",workDir_path+"input.inp"};
Process p = rt.exec(command);
p.waitFor();
p.destroy();
} catch(Exception exc){ }
The path strings contain the absolute paths to both my program.exe and my working directory.
Any suggestion or idea why my program.exe called from inside my java code does not write the output.out file while this does happen in the command line mode? Maybe a suggestion on how to solve this?
thanks in advance,
- 02-25-2010, 10:58 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't do catch(Exception exc){ }
That will hide any exceptions.
Do catch(Exception exc){exc.printStackTrace(); } instead.
- 02-25-2010, 01:04 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
I did add the exc.printStackTrace(); in the exception handling part, but i didn't mention it because I think it has no impact on the problem I am dealing with.
- 02-25-2010, 01:11 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
So you don't get any output at all from the console?
Which directory are you checking for the output file?
- 02-25-2010, 01:19 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
When the external program is called in my java code, it executes normally without producing errors. My console displays the intermediate messages I expect, similar to "Program Running..." and terminates in a normal fashion as well.
It's as if my external program.exe merely forgets to write its results into a new file (ic: output.out).
- 02-25-2010, 01:31 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Which directory are you checking for the output file?
- 02-25-2010, 02:38 PM #7
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
Problem solved.
The problem was caused by my mistake.
The location of my Java project in Eclipse was not identical to the working directory used when calling the external programs. Apparently, they should be equal.
@r035198x: it was your remark that made me look into this. Thanks a lot! It helped me tremendously.
Similar Threads
-
program terminates itself and leave log file called hr_err_pid in desktop
By rinza in forum New To JavaReplies: 3Last Post: 03-13-2012, 09:28 AM -
ok so i have to write a program called FourRectanglePrinter
By jcoon3 in forum New To JavaReplies: 0Last Post: 09-22-2009, 07:15 PM -
Execute external file/program
By sirwiggles in forum New To JavaReplies: 3Last Post: 04-21-2009, 11:35 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Use a external file in my program
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks