Runtime.exec() opening application in background

859 views Asked by At

I m using runtime.exec() to open an application and perform some task on it, but it opens in background and i'm not able to perform any task as planned, so can anybody suggest how to bring my app to foreground so that its active to perform the required task. i'm using the below code

try {
        Runtime.getRuntime().exec("C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Thread.sleep(3000);

    System.out.println("Running robot class");
     Robot rb;
    try 
    {
        rb = new Robot();
         rb.keyPress(KeyEvent.VK_ENTER);
         rb.keyRelease(KeyEvent.VK_ENTER);

         Thread.sleep(3000);

         rb.keyPress(KeyEvent.VK_ENTER);
         rb.keyRelease(KeyEvent.VK_ENTER);
         Thread.sleep(3000);

    } 
    catch (AWTException e) {

        e.printStackTrace();
    }           
1

There are 1 answers

0
jai Nagarajan On

Remove the thread.sleep and try with below,

rb = new Robot(); rb.delay(3000);

It's opening for me