有没有办法从 .ahk 文件中读取变量并在另一个批处理脚本文件中使用它

问题描述

我不知道读取另一个文件中另一个变量的好方法

FileReader.bat

    @echo off

:: Some how read VarX in the ahk file and then save it as another variable

SET VarXReading=%VarX%

echo %VarXReading%

pause

FiletoBeRead.ahk

VarX = 69420

解决方法

您可以将该变量作为参数传递给批处理文件。例如

ahk 脚本:

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Do whatever you need to here
VarX := 69420

Run batch.bat %VarX%

批处理脚本:

@echo off
SET VarXReading=%1
echo %VarXReading%
pause

只需确保批处理脚本和 ahk 脚本在同一目录中即可使用