[SOLVED] Is it harmful to close a command prompt/power shell during an operation?

Status
Not open for further replies.

ShangWang

Reputable
Mar 26, 2021
617
2
4,885
I was using Get-AppxPackage Microsoft.YourPhone -AllUsers | Remove-AppxPackage to uninstall the phone app, and probably closed the application a bit too quickly, but the operation did complete and the app was removed.

I was wondering if I close the command window while an operation is running, will the operation cancel or continue running in the background for something like sfc /scannow? If it's something that "initializes" a simple operation like removing an app, is it ok to quickly close the window?
 
Solution
it means that if you ran a command like Diskpart clean on a hdd and closed the window, there is a good chance the operation is still occurring in the background. Some tasks can create jobs for the PC, I am not sure about SFC though.
it means that if you ran a command like Diskpart clean on a hdd and closed the window, there is a good chance the operation is still occurring in the background. Some tasks can create jobs for the PC, I am not sure about SFC though.
 
  • Like
Reactions: ShangWang
Solution
it means that if you ran a command like Diskpart clean on a hdd and closed the window, there is a good chance the operation is still occurring in the background. Some tasks can create jobs for the PC, I am not sure about SFC though.
I believe windows would not allow a manual closing of these processes ONLY if they could potentially cause damage to the system. From what I know closing the command prompt will stop the process before closing, so a diskpart clean would likely stop in the middle.
 
Closing a command window while a command is running is akin to pulling the rug out from under someone. The operation will NOT exit cleanly and may leave things a mess depending upon what was going on at the time. Not all commands launch separate threads. And Windows will not prevent you closing a command window on a critical command. When you click the "X" to close the window it closes NOW.
 
  • Like
Reactions: ShangWang
Closing a command window while a command is running is akin to pulling the rug out from under someone. The operation will NOT exit cleanly and may leave things a mess depending upon what was going on at the time. Not all commands launch separate threads. And Windows will not prevent you closing a command window on a critical command. When you click the "X" to close the window it closes NOW.
I see, what about choosing to enter "exit" or ctrl + c?
Does doing those commands not add any safety to closing the command prompt and they're the same as just closing the window?
 
Interrupting a command at any time by any method can lead to unintended consequences at any time. Best rule is to just leave it alone and let it run its course. The only exception being those rare cases where things lock and there is no alternative.
Makes sense, I think I would still type "exit" to make sure the window can be safely closed. Thanks!
 
its like restarting during a windows update. its not going to be pretty afterwards.

i don't use cmd much so if i do its to run sfc or dism and both have end messages. So I wait till they obviously finished, and click X. Never really used exit command, expect the X button performs an exit command.
you can run cmd minimized meaning it doesn't show the window - https://stackoverflow.com/questions/4277963/how-to-call-cmd-without-opening-a-window/28501808
not exactly useful here but shows that just cause its not showing, doesn't mean its not working.
 
  • Like
Reactions: ShangWang
its like restarting during a windows update. its not going to be pretty afterwards.

i don't use cmd much so if i do its to run sfc or dism and both have end messages. So I wait till they obviously finished, and click X. Never really used exit command, expect the X button performs an exit command.
you can run cmd minimized meaning it doesn't show the window - https://stackoverflow.com/questions/4277963/how-to-call-cmd-without-opening-a-window/28501808
not exactly useful here but shows that just cause its not showing, doesn't mean its not working.
I see, I would take the precaution of waiting for when it's finished too.

Although commands can only be done one after another, using the exit command even if it was early would mean windows would have to wait for the previous process to be done first, then it would safely exit by processing the "exit" command. This is why I am suggesting this might add a little more security when not sure of when to exit the window.
 
it really depends what you are doing. Some things are probably more dangerous to close early than others. There is no one rule.

closing out of a diskpart clean which wipes hdd is likely more dangerous than closing out of the command that just lists what drivers are on your pc.

Use common sense, and you be fine.
 
  • Like
Reactions: ShangWang
Status
Not open for further replies.