Exchange CMD and Autohotkey environment variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Exchange CMD and Autohotkey environment variables

22 Dec 2022, 06:34

I'm rethinking to theme the Everything (file search). It has a small utility for (es.exe) to perform searches in the command line. If you create a .bat file (or execute it sequentially in the command line), it works:

Code: Select all

set "File=microsoft azure TTS.ahk" ; Code of a .bat file
d:\Utilidades\Everything\es.exe %File% > h:\OutFile.txt
The time I read that the && symbol chains various commands, as in the following example (which does not work. /k is equivalent to pressing "enter"):

Code: Select all

Run, %comspec% set "File=microsoft azure TTS.ahk" /k && d:\Utilidades\Everything\es.exe %File% > h:\OutFile.txt /k
What would be the correct way to create the code line that executes the equivalent commands in a .bat file?

I find myself with another difficulty. Ideally, the variable %File% was defined in AutoHotkey, but the following code does not work:

Code: Select all

File="microsoft azure TTS.ahk"
run, d:\Utilidades\Everything\es.exe %File% > h:\OutFile.txt
How is a variable from the AutoHotkey environment shared with the command line environment?

(If the RunCMD() viewtopic.php?f=6&t=74647&start =200 function is used, but not if it is suitable for the problem you are facing, you should not create the code to make it work)
------
For "Everything" to read environment variables, ask on the "Everything" forum itself https://www.voidtools.com/forum/viewtopic.php?p=51625#p51625
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Exchange CMD and Autohotkey environment variables

22 Dec 2022, 10:21

Hello,
The time I read that the && symbol chains various commands
Your reading about && was not reading about AutoHotkey.

https://www.autohotkey.com/docs/v1/Variables.htm#and

Code: Select all

file = microsoft azure TTS.ahk
out  = %A_ScriptDir%\out.txt
app  = d:\Utilidades\Everything\es.exe
RunWait, "%app%" -export-txt "%out%" "%file%",, Hide
Run, %out%
Explained: RunWaitEverything
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Exchange CMD and Autohotkey environment variables

22 Dec 2022, 11:00

What gibberish, you have to create three different variables!, jajaja. Thank you very much mikeyww :thumbup: (ah, it works).

(About the "&&" symbols are for chaining, I was guided by this thread, but I don't think I read the whole thing: viewtopic.php?t=14162)
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Exchange CMD and Autohotkey environment variables

22 Dec 2022, 11:07

OK, my information was wrong in this context of using ComSpec. In any case, you do not need ComSpec here, as you do not need > because you have a command-line option to export. Enjoy!

Regarding variables, see https://www.autohotkey.com/docs/v1/Variables.htm#Intro.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Exchange CMD and Autohotkey environment variables

22 Dec 2022, 13:18

At my age I no longer retain anything I read (and/or have always retained information poorly). In other words, when I have a problem I look for the solution. I review my own scripts for solutions already found and used successfully. Thanks again, mikeyww :xmas:

(when I wrote "but I don't think I read the whole thing", in the previous post, I was referring to myself)
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Exchange CMD and Autohotkey environment variables

23 Dec 2022, 12:15

Hi.

I share the following line of code for anyone interested in the topic.

I asked about other issues in the Everything forum https://www.voidtools.com/forum/viewtopic.php?f=4&t=12490&p=51747#p51747, and they gave me this solution to paste into the clipboard the results of a search. The "philosophy" of this way of doing things is totally different. Use the "space". %comspec% for the same purpose as the one proposed here (although under a different orientation and goal).

Code: Select all

runwait, %comspec% /c chcp 65001 & es.exe namefile | clip
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Exchange CMD and Autohotkey environment variables

23 Dec 2022, 12:53

Yes, a good option if no output file is needed. Thanks!

To clarify Windows batch syntax for ampersand:

&: "Chain" or sequence commands on one line

&&: The second command executes only if the first command succeeds

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, peter_ahk, Spawnova and 342 guests