MATLAB Answers

How to close system command prompt opened by MATLAB !command?

52 views (last 30 days)
I've seen similar questions but not ones that involve opening the command window/terminal via "!". I'm using a MATLAB-to-Python socket connection and I want to close the command window/terminal at the end.
% Start the echo server in python.
!python &
% Do some stuff with my sockets.
% Close the connection.
%%% Close the terminal here?
The opened command line/terminal says at the top "C:\WINDOWS\SYSTEM32\cmd.exe" following the closing of the socket.


Dominik Mattioli
Dominik Mattioli on 10 Jul 2019
A quick search suggestes that this should work, but it doesn't?
[status, result] = system('TASKKILL -pid "C:\WINDOWS\SYSTEM32\cmd.exe"')
status =
result =
'ERROR: Invalid query

Sign in to comment.

Accepted Answer

Jalaj Gambhir
Jalaj Gambhir on 19 Jul 2019
As rightly pointed out by @Walter, the command
system('Taskkill/IM cmd.exe')
closes all the opened command windows.


Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!