-3

How to close opened windows command line? I started in cmd server for reporting tests and i have info about:

"Starting web server... Press 'Ctrl+C' to exit"

How to send "ctrl+c" and close cmd in java?

2
  • It's unclear what you are asking, do you want to send a ctrl+c equivalent signal to the Command (cmd) application in Windows to process and then close the Command window from your java program? I don't think it is possible at all. Commented Feb 25, 2019 at 10:17
  • I would like to close cmd but I can't do it without press ctr+c. How to close/kill cmd window? Commented Feb 25, 2019 at 10:25

1 Answer 1

0

First you need to get the PID of this Process and then destroy it this might help you

The right way to kill a process in Java

Kill a process based on PID in Java

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

5 Comments

can you explain more why its not woking? if you want to close cmd String cmd = "taskkill /F /IM cmd.exe"; Runtime.getRuntime().exec(cmd);
I have information "Starting web server... Press 'Ctrl+C' to exit". If use "taskkill /F /IM cmd.exe" nothing will happen. But if I manually press ctrl+c on cmd then I can use "taskkill /F /IM cmd.exe" ad close cmd.
Well, you can write a Code in java to open cmd and run the server you want then terminat it and close it when you want. stackoverflow.com/questions/7433073/… and insted of sending Ctrl+C you can write "kill -SIGINT processPIDHere"
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.
"taskkill /F /IM cmd.exe" that will close cmd.exe. You were supposed to provide name of application you want to kill.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.