how to send multiple line to comspec??

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

how to send multiple line to comspec??

01 Aug 2020, 06:37

hi all

normally we use winactive to send text to cmd.EXE like:

Code: Select all

run, %comspec% /k
WinWait, %comspec%
WinActivate
Send stop{Enter}
sometime can run command like :

Code: Select all

run,%comspec% /k ver&time /t&date /t`n
or

Code: Select all

objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(ComSpec " /c stop")

strStdOut := ""
while, !objExec.StdOut.AtEndOfStream
{
       strStdOut := objExec.StdOut.ReadAll()
}



but normally is single command
can someone know how to send command to cmd and use multiple line ??
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: how to send multiple line to comspec??

01 Aug 2020, 07:41

example , send commands when start and later followed command ( if needed )

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.
wa:=a_screenwidth,ha:=a_screenheight,W :=(wa*50)/100,H :=(ha*92)/100
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
)
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,%w%,%h%       ;- move DOS window to the defined position
WinWaitactive, ahk_pid %pid2%
controlsend,,{text}ver`n,ahk_pid %pid2%
sleep,1000
controlsend,,{text}echo @@@ -- quit in 5 seconds`n,ahk_pid %pid2%
sleep,5000
controlsend,,{text}exit`n,ahk_pid %pid2%
return
;=======================================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 348 guests