Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    11
    Rep Power
    0

    Default 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,

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Don't do catch(Exception exc){ }
    That will hide any exceptions.
    Do catch(Exception exc){exc.printStackTrace(); } instead.

  3. #3
    Join Date
    Feb 2010
    Posts
    11
    Rep Power
    0

    Default

    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.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    So you don't get any output at all from the console?
    Which directory are you checking for the output file?

  5. #5
    Join Date
    Feb 2010
    Posts
    11
    Rep Power
    0

    Default

    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).

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Which directory are you checking for the output file?

  7. #7
    Join Date
    Feb 2010
    Posts
    11
    Rep Power
    0

    Default

    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

  1. Replies: 3
    Last Post: 03-13-2012, 09:28 AM
  2. Replies: 0
    Last Post: 09-22-2009, 07:15 PM
  3. Execute external file/program
    By sirwiggles in forum New To Java
    Replies: 3
    Last Post: 04-21-2009, 11:35 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Use a external file in my program
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •