我正在运行AutoIt脚本,该脚本调用另一个AutoIt文件。如何将变量值从第一个脚本传递到下一个脚本?
答案 0 :(得分:2)
您需要了解变量的范围概念(Dim,Global& Local变量)。
来自AutoItHelp
Dim,Local和Global之间的区别在于它们的创建范围:
- Dim =本地范围如果变量名称不是全局存在的(在这种情况下它会重用全局变量!);
- Global =强制在全局范围内创建变量;
- Local =强制在Local / Function范围内创建变量。
两个文件的示例: main.au3 和 constantes.au3 。
#include-once
; Declaration of global variables
Global $name_application = "Foo"
Global $year = 2014
#include <constants.au3>
Func _foo()
ConsoleWrite("In function _foo() name_application is available and it's equals = "&$name_application&@CRLF)
Local $year2= 2014
EndFunc
ConsoleWrite("In main.au3 global variables are available"&@CRLF)
ConsoleWrite("For example, name_application = "&$name_application&@CRLF)
ConsoleWrite("But the local variable year2 isn't available here")
更多信息请点击此处:http://www.autoitscript.fr/autoit3/docs/keywords/Dim.htm
答案 1 :(得分:1)
使用命令行界面以便在两个文件之间进行通信。 必须编译文件2.
File1.exe:
$ThisIsVariableFromFIle1 = "This is some text."
Run("File2.exe " & $ThisIsVariableFromFIle1)
File2.exe:
MsgBox(0,"This is the whole commandline I got", $CmdLineRaw)
MsgBox(0,"This is part one", $CmdLine[1]); This
MsgBox(0,"This is part two", $CmdLine[2]); is
MsgBox(0,"This is part three", $CmdLine[3]); some