Results 1 to 6 of 6
  1. #1
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default Another question about java's Runtime.exec

    Its hard to explain but I'll take a crack at it. I have this java program that runs an executable. The executable works perfectly if I just run it from the command line. But if I use the java's Runtime.getRuntime().exec(cmd) command, it doesn't work correctly. Now I'll explain what works correctly exactly means. The executable works correctly, if its able to read the filename passed in by the command line arguments and read the data and process it. So when I use the command line explicitly, it works fine. It reads the filename and process the data and outputs it to the console. But when I use java to evoke it, the executable isn't able to read the file. Now I suspect the problem is that java redirects the output and the input stream or something of that nature, so the executable can only input and output to the standard console and not to file? That statement is probably wrong but its a guess. Well my question is( if you read this far thanks), that how would I be able to fix the problem so the executable would be able to read in from the file. Thanks for reading. Hoping desperately that someone can help me.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    its possible there are environment variables that are required for running the program, (PATH, current working folder?) and these are missing when using runtime.exec.
    also it might be possible the runtime.exec is not passing the command line parameter correctly to the external process being launched.
    Have you tried the ProcessBuilder API?

  3. #3
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    I don't think the executable needs any environment variables to be set. I hope not. If so I really don't know much about environment variables. If I manually use the command line interface it works fine so it might be runtime.exec. I will give ProcessBuilder a shot. I will check back here very often if anyone has more advice. Thanks.

  4. #4
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Also if I haven't mentioned, the filename is in the same directory as the executable.

  5. #5
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    I tired using the Processbuilder and the same thing happens. Maybe I do have to set the path environment. Any help with that? I'm not sure exactly what to do. Thanks.

  6. #6
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Oh my god, I got it!!!!!!!!!!!!!!!!!!!! It was the environment variable. It didn't find the file because it looked for the file in the current directory that netbeans project was in and not the directory that I set it for the ProcessBuilder. I am so happy! Thanks so so much guys.
    I wish I can give you guys a hug lol.

Similar Threads

  1. Question about java's Runtime.exec
    By Prompt in forum New To Java
    Replies: 3
    Last Post: 01-13-2011, 10:48 PM
  2. question with command prompt and Runtime.exec()
    By mosquetero in forum New To Java
    Replies: 3
    Last Post: 08-11-2009, 01:08 PM
  3. runtime.exec
    By cotede2 in forum Advanced Java
    Replies: 3
    Last Post: 04-17-2009, 06:18 PM
  4. help with Runtime.exec()
    By Lanfear in forum New To Java
    Replies: 18
    Last Post: 12-16-2008, 12:09 PM
  5. Runtime.exec()
    By hknyo in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 01:40 AM

Posting Permissions

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