Sending text to command prompt

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
noobcoder
Posts: 2
Joined: 21 Jul 2016, 16:32

Sending text to command prompt

21 Jul 2016, 17:08

I'm trying to make a script that will open the command prompt and input some text to run a command. I run into an issue that certain characters that get sent as different characters. Here's an example.

run, cmd.exe /k cd <location>
Sleep 500
Send :/.",

Result:

<location>>^:/@?

The characters :/.", are sent as ^:/@? to the command prompt, respectively.

If I get rid of the sleep command it works fine but I need it. Otherwise the text is sent before the command prompt is in focus, sending the input to whatever window was previously in focus

How can I get it to sleep for half a second and then properly send those characters? I need those specific characters in some of my commands.
User avatar
TLM
Posts: 1606
Joined: 01 Oct 2013, 07:52
Contact:

Re: Sending text to command prompt

21 Jul 2016, 18:21

Not sure why you'd need to cd to a dir when AHk offers many built in approaches for running binaries etc but..
try

Code: Select all

SomePath = *THE FOLDER*
run, cmd.exe /k cd "%SomePath%",,, cmdPID
WinWait, ahk_pid %cmdPID%
Send :/.",
see: Run > OutputVarPID & WinWait in the help file for more info
htms
noobcoder
Posts: 2
Joined: 21 Jul 2016, 16:32

Re: Sending text to command prompt

21 Jul 2016, 19:00

This doesn't seem to solve the main issue.

I use the command "Send :/."," but this is what appears in cmd. http://puu.sh/q9Wam/70eb5a8c62.png
User avatar
TLM
Posts: 1606
Joined: 01 Oct 2013, 07:52
Contact:

Re: Sending text to command prompt

21 Jul 2016, 20:32

works for me. try SendInput :/."," or SendEvent :/.","
either one also work for me
Guest

Re: Sending text to command prompt

22 Jul 2016, 01:37

Sending text to a cmd window can be tricky at times and can behave irregular in my experience. You can also try https://autohotkey.com/board/topic/25446-consolesend/ which has given me some good results in the past.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo and 149 guests