2

I am trying to run a .bat file from my java code and I'm using the ProcessBuilder.java functionality as follows:

    String[] hubCmd = new String[]{"cmd.exe", "/C", "startHub.bat"};
    ProcessBuilder pbHub = new ProcessBuilder(hubCmd);
    pbHub.directory(new File("C:\\java\\selenium\\"));
    Process hubP = pbHub.start();

This seems to work, kicks of a java process and associated cmd process, but the command window is not displayed. Am I missing something or is this correct functionality?

Thanks in advance.

5
  • Sounds like correct functionality to me Commented Jul 8, 2014 at 7:48
  • 1
    why do you want it to open command window ? just to see logs ? if so you can actually stream back the output of that process Commented Jul 8, 2014 at 7:50
  • Admittedly an element of laziness, although I do need to sort out logging the output. But still, just a bit annoying that there is no switch to tell it to actually display the cmd window. Commented Jul 8, 2014 at 7:53
  • Even if you opened one CMD window on your Windows machine, you can start other CMD processes (inside) which won't open other windows. Commented Jul 8, 2014 at 7:57
  • Runtime.getRuntime().exec("cmd.exe /C start"); this probably should display the command window Commented Jul 8, 2014 at 8:07

1 Answer 1

3

Java's Process is meant to execute a command, and so it does with cmd.exe.

What you see is correct. cmd.exe does not have a "feature" for displaying a window.

The "window" you normally see is a terminal emulation or some such thing which in turn (like your Java program!) can execute another program, i.e., cmd.exe

It is the same with Linux, where an xterm executes a shell (the command interpreter). No shell (in the classic style) can display a "window".

You can make your Java program the "window"!

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

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.