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

Vika
  • 153
  • 1
  • 1
  • 10
  • What happens if you run the command manually with /B argument. Does it work – Ramesh Jul 26 '15 at 07: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 '15 at 07:30

2 Answers2

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

Community
  • 1
  • 1
Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • 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 '15 at 06:42
0

Use /B with /wait it works.

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

Athena
  • 3,200
  • 3
  • 27
  • 35