How to auto close cmd after it has finished executing?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

How to auto close cmd after it has finished executing?

Post by newcod3r » 28 Oct 2021, 21:59

image.png
image.png (12.93 KiB) Viewed 1966 times
note I'm not asking about silent execution, but how to know when cmd has completed and thus can exit by itself.

User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: How to auto close cmd after it has finished executing?

Post by Masonjar13 » 29 Oct 2021, 00:03

Assuming you're typing this out, just add & exit to the end of the command.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: How to auto close cmd after it has finished executing?

Post by newcod3r » 29 Oct 2021, 00:28

that's easy. Thank you!

garry
Posts: 3788
Joined: 22 Dec 2013, 12:50

Re: How to auto close cmd after it has finished executing?

Post by garry » 29 Oct 2021, 05:03

also : run,%comspec% /c , means close DOS window after command finished , %comspec% /k , keep DOS window
an example

Code: Select all

#warn
#NoEnv                       ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetKeyDelay, 80, 10
e4x=
(Ltrim join&&
@echo off
echo date=
date /t
echo time=
time /t
cd\
)
title2=DOS_TEST
run, %comspec% /T:0A /k "title %title2%&mode con lines=4000 cols=120&%e4x%,,,pid2
WinWait, ahk_pid %pid2%
WinMove, ahk_pid %pid2%, ,1,1,,                           ;- move DOS window to the defined position
WinWaitactive, ahk_pid %pid2%
SendInput {text}ver`n
sleep,1000
controlsend,ahk_parent,{text}dir`n,ahk_pid %pid2%
ControlSend,ahk_parent,{text}@echo Quit this DOS in 6 seconds`r,ahk_pid %PID2%
sleep,6000
ControlSend,ahk_parent,{text}exit`r,ahk_pid %PID2%                ;-- quit DOS after 6 seconds
return

Post Reply

Return to “Ask for Help (v1)”