0

I'm making a program which runs C++ using G++ and to build/run it, it creates a .bat file which should then be ran in a new cmd window. From Java, I can run commands, but just running a command doesn't open cmd, so I need to open cmd and also run a command in that cmd window in one command. How do I do this?

  • What have you tried? It should be as simple as running the batch file within the command prompt. – Ramhound Mar 2 '16 at 20:05
  • As I'm using Java, I need to run cmd and a command in cmd, both in the same line. I've tried cmd -c <batch file path> or something along those lines. – Zac Garby Mar 2 '16 at 20:17
  • reach a .bat file then run that. The output of all commands, will remain in the single command prompt window, which seems to fit what you want. If it does not then provide specific examples of what you actually do want. – Ramhound Mar 2 '16 at 20:21
  • 2
    This is really a programming question and should be asked on Stack Overflow – DavidPostill Mar 2 '16 at 22:02
  • 1
    You should also read cmd - Start a new CMD shell and (optionally) run a command/executable program. It tells you exactly what arguments you can pass to cmd. Hint -c isn't one of them. – DavidPostill Mar 2 '16 at 22:04
1

How can I run cmd and execute a batch file

From Java, I can run commands, but just running a command doesn't open cmd, so I need to open cmd and also run a command in that cmd window in one command.

How do I do this?

From your Java program use the following:

cmd /c batch.cmd

This will start a new cmd shell, run batch.cmd and then terminate the shell. See cmd for more information.


Further Reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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