-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?

John
  • 1
  • 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. – Joakim Danielson Feb 25 '19 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? – John Feb 25 '19 at 10:25

1 Answers1

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

kalix
  • 57
  • 1
  • 6
  • 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); – kalix Feb 25 '19 at 10:37
  • 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. – John Feb 25 '19 at 10:51
  • 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. https://stackoverflow.com/questions/7433073/how-to-write-into-and-read-from-command-line-in-java and insted of sending Ctrl+C you can write "kill -SIGINT processPIDHere" – kalix Feb 25 '19 at 12:10
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) 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.](//stackoverflow.com/help/deleted-answers) – double-beep Feb 25 '19 at 18:45
  • `"taskkill /F /IM cmd.exe"` that will close cmd.exe. You were supposed to provide name of application you want to kill. – Antoniossss Feb 26 '19 at 09:48