1

I nead to run some .exe file minimized with arguments. Right now with my code i can run it in normal window. Here is my code:

ProcessBuilder pb = new ProcessBuilder(directoryString, myArg1, myArg2);
Process pr = pb.start();

I found this solution:

start /min "" directoryString

But i don't know how to use it on ProcessBuilder with process with arguments.

Higu
  • 193
  • 1
  • 1
  • 10

2 Answers2

0

start is actually a Windows cmd command.

Thus: make that implicit by calling

cmd.exe /start.... 

via the Java process builder; as outlined here.

What I mean is: first open a windows console/terminal; and built a command like

cmd.exe /c start /min .... 

and when that works to run your program; then use that string as input for the Java ProcessBuilder. You might also find some more helpful examples here.

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • When i'm adding `start /min` before the directory, i'm getting exception _The system cannot find the file specified_ – Higu Feb 26 '17 at 20:42
  • I am not an Windows expert: my suggestion: build a command that works on the command line and that includes cmd.exe itself... And when that works take that string into Java. – GhostCat Feb 26 '17 at 20:46
  • I tried, i found string that works in command line: `start /min directoryString myArg1` but in Process Builder i can't just write this string. Process Builder is reading first string as directoryString, second as myArg1. When i'm putting directoryString and myArg1 together, in one string, ProcessBuilder is reading it as only directoryString and can't run .exe. – Higu Feb 26 '17 at 20:49
  • Some more updates for you in my answer; hope they help. And hint: try running a search engine, that might help ... good luck and good night from end ... for today. – GhostCat Feb 26 '17 at 20:52
0

I did it so:

    String args = "myArg1";
    String cmd = "cmd.exe /C START /MIN directoryString ";
    Runtime.getRuntime().exec(cmd + args);

After directoryString it need to be a one space, otherwise cmd will read it as only one string without spaces and try to open not existing file.

Higu
  • 193
  • 1
  • 1
  • 10