Page 1 of 1

How can I make `send` give input to Windows cmd terminal?

Posted: 06 Sep 2018, 23:59
by MortenZdk
I would like to send some text to a Windows cmd terminal, so I made this simple AutoHotKey .ahk script file:

Code: Select all

^!+T::Send Hello
However, the text "Hello" does not show in the cmd terminal windows when I press Ctrl + Alt + Shift + T, but it works fine when I use it from a simple text editor.

How can I make send give input to Windows cmd terminal?

Re: How can I make `send` give input to Windows cmd terminal?  Topic is solved

Posted: 07 Sep 2018, 03:15
by YMP2
It works on Windows 10. What version of Windows do you use?

Re: How can I make `send` give input to Windows cmd terminal?

Posted: 07 Sep 2018, 04:43
by KRG-23
I'd try to use the Run function maybe?

https://autohotkey.com/docs/commands/Run.htm
And this exemple :

Code: Select all

MsgBox % RunWaitMany("
(
echo Put your commands here,
echo each one will be run,
echo and you'll get the output.
)")

RunWaitMany(commands) {
    shell := ComObjCreate("WScript.Shell")
    ; Open cmd.exe with echoing of commands disabled
    exec := shell.Exec(ComSpec " /Q /K echo off")
    ; Send the commands to execute, separated by newline
    exec.StdIn.WriteLine(commands "`nexit")  ; Always exit at the end!
    ; Read and return the output of all commands
    return exec.StdOut.ReadAll()
}

Re: How can I make `send` give input to Windows cmd terminal?

Posted: 07 Sep 2018, 05:09
by garry
@KRG-23, thank you , nice example to send/read hidden DOS
example send commands to DOS at start and 2 seconds later ( /T:0A is green color )

Code: Select all

#warn
setworkingdir,%a_scriptdir%
SetBatchLines, -1
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
cd\
dir
)
title2=DOS_TEST
run, %comspec% /T:0A /k "title %title2%&mode con lines=4000 cols=120&%e4x%,,,pid2
 WinWait, ahk_pid %pid2%
 sleep,2000
 controlsend,,ver`n,ahk_pid %pid2%
return

Re: How can I make `send` give input to Windows cmd terminal?

Posted: 07 Sep 2018, 08:35
by MortenZdk
YMP2 wrote:It works on Windows 10. What version of Windows do you use?
I use Windows 10 also, fully updated.

However, your comment made me examine further, and I found out that the cmd was started through a link, and for some reason this specific link did not receive the AHK send text.

I replaced the link with an new link, based on c:\Windows\System32\cmd.exe, and then it works.

Pretty odd, but thanks for telling that it worked on your machine.

Have a nice weekend.