Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java exec

  • 12-05-2010 10:12am
    #1
    Registered Users, Registered Users 2 Posts: 427 ✭✭


    Hi,
    I have a program which cannot run on windows. I have managed to get it to run in Cygwin and now I am hoping to call the program from a windows Java application using Runtime.exec. I know this is messy but I don't have the option of switching OS atm.


    So what I need is to launch the cygwin terminal and pass new commands to that terminal in order to navigate to my program and execute it. Does anyone have examples of this?

    My problem is that I can execute a command but I can't get any new output when inputting new commands.

    I'll give an example using cmd instead of cygwin:
    String line;
        OutputStream stdin = null;
        InputStream stderr = null;
        InputStream stdout = null;
    
          // launch EXE and grab stdin/stdout and stderr
          Process process = Runtime.getRuntime ().exec ("cmd.exe", new String [] {"/K"});
          stdin = process.getOutputStream ();
          stderr = process.getErrorStream ();
          stdout = process.getInputStream ();
      
          // a new command into cmd
          line = "dir" + "\n";   
          stdin.write(line.getBytes() );
          stdin.flush();
    
          stdin.close();
          
          // clean up if any output in stdout
          BufferedReader brCleanUp = 
            new BufferedReader (new InputStreamReader (stdout));
          while ((line = brCleanUp.readLine ()) != null) {
            //System.out.println ("[Stdout] " + line);
          }
          brCleanUp.close();
          
          // clean up if any output in stderr
          brCleanUp = 
            new BufferedReader (new InputStreamReader (stderr));
          while ((line = brCleanUp.readLine ()) != null) {
            //System.out.println ("[Stderr] " + line);
          }
          brCleanUp.close();
    

    I don't get any errors. It just executes with no output.
    Thanks

    Edit: I have tried using both \n and \r and both in order to indicated carriage return when writing to the cmd process.


Comments

Advertisement