0

I'm trying to execute some batch file from java class. I want the batch to run without opening cmd window and I want to wait till it is completed.

When using the command below (without the backgroung) - it works perfectly:

String executeCmd = "cmd /c start /wait " +config.getJarPath()+ " --context_param Path=" +folderName;
        final Process process = run.exec(executeCmd);
        process.waitFor();

But when I'm adding the /b (run in background) the batch file is not running:

String executeCmd = "cmd /c start /B /wait " +config.getJarPath()+ " --context_param Path=" +folderName;
        final Process process = run.exec(executeCmd);
        process.waitFor();

Do you have any idea what can it be?

Thanks a lot

2
  • What happens if you run the command manually with /B argument. Does it work
    – Ramesh
    Jul 26, 2015 at 7:13
  • Just tried to do this and I see something wierd.. The context_param I'm sending being messed up somehow. one of the slashes being converted to ♀ (some wierd char)
    – Vika
    Jul 26, 2015 at 7:30

2 Answers 2

0

Using the start /b command tag simply starts the program in the current window.

B           Start application without creating a new window. 

If you want to start the batch file as a hidden process there is a simple vb script which does this.

Alternatively you could use a Batch-To-Exe converter and when converting it specify you would like the exe to be a Ghost Application

1
  • Thanks for your answer. Didn't work for me. Decided to just go with /min.. not a perfect solution but I can deal with it.
    – Vika
    Jul 27, 2015 at 6:42
0

Use /B with /wait it works.

E.g. cmd /c start /B /wait yourbatfile.bat

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.