简体   繁体   中英

Runtime.exec() opening application in background

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();
    }           

Remove the thread.sleep and try with below,

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

It's opening for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM