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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MortenZdk
Posts: 9
Joined: 25 Aug 2018, 06:02

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

06 Sep 2018, 23:59

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?
YMP2
Posts: 48
Joined: 20 Apr 2014, 06:55

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

07 Sep 2018, 03:15

It works on Windows 10. What version of Windows do you use?
User avatar
KRG-23
Posts: 19
Joined: 07 Jun 2016, 05:45
Location: France

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

07 Sep 2018, 04:43

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()
}
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

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

07 Sep 2018, 05:09

@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
MortenZdk
Posts: 9
Joined: 25 Aug 2018, 06:02

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

07 Sep 2018, 08:35

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy and 167 guests