java - How to start a program with command line arguments on Windows' cmd and force it to run foreground? -


I am performing an offline smoking test (SELENIUM) and enables macros in the Excel spreadsheet that is generated by the system I had to use an alternative solution, where in Java code, I open the Excel spreadsheet, save it and close it, so that I can run the exam and write the value on this spreadsheet. To open Excel spreadsheets (I want to set up to trust all macros), I wrote the following Java code, where I use the command line command to execute it:

 < Code> @ then ("Enable Worksheet Macro") throws Public Zero Enabled Worksheet (Macros), interrupted, exception, IOException, AWTException {final string diretory = "c: \\ automation \\"; Last file file = new file (synrory); Last File [] Files = file.listFiles (New FileFilter () {@ Override Public Boolean Accept (File File) {return file.getName (). ToLowerCase (Locale.glsh) .endsWith (".xls");}} ); If (files.length & gt; 1) {System.out.println ("too many files"); } And if (files.length == 1) {final string filename = files [0] .getAbsolutePath (); Last processbilder PB = new process builder ("CMD", "/ c", "start", file name); Final process p = pb.start (); P.waitFor (); Thread.Sleep (5000); Final Robot R = New Robot (); R.keyPress (KeyEvent.VK_ALT); R.keyPress (KeyEvent.VK_F4); Thread.Sleep (200); R.keyRelease (KeyEvent.VK_F4); R.keyRelease (KeyEvent.VK_ALT); Thread.Sleep (200); R.keyPress (KeyEvent.VK_ENTER); Thread.Sleep (200); R.keyRelease (KeyEvent.VK_ENTER); Thread.Sleep (200); R.keyPress (KeyEvent.VK_ENTER); Thread.Sleep (200); R.keyRelease (KeyEvent.VK_ENTER); Thread.Sleep (200); }}  

As you can see, just after opening the Axl file, I just press ALT + F4 twice (this closes the file and saves it). It was working fine until I run this code in another environment, where it opens the excel file, this background is running.

Is there any way that I can ensure that the program runs the foreground?

Edit : I got this question on the SU, where there is a similar problem to the man, but no reply so far:


Comments