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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

When i'm adding start /min before the directory, i'm getting exception The system cannot find the file specified
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.
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.
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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.