数据未保存在 autoit 中
我正在使用一个文件将数据发送到全局文件中的全局变量,然后让另一个文件尝试从全局文件中检索该数据。
示例:
主文件将数据发送到全局文件,其他文件从全局文件获取数据
由于某种原因,数据没有被保留。当我从全局文件中提取数据时,它不在那里。这是为什么呢?
下面是一些示例代码:
;main.au3
#include-once
#include "global.au3"
$g1 = "stuff"
$g2 = "stuff"
Run("copy.exe")
;global.au3
#include-once
Global $g1 = ""
Global $g2 = ""
;copy.au3
#include-once
#include "global.au3"
MsgBox(0, $g1, $g2)
main.au3 和 copy.au3 已内置到 .exe 中,我双击 main 来运行它。
结果: $g1 和 $g2 等于“”和“”,而它应该打印“stuff”
I am using one file to send data to global variables in a globals file and having another file try and retrieve that data from the globals file after.
Example:
Main file sends data to global file and other file gets data from global file
For some reason the data isn't being preserved. When I pull the data from the global file it's not there. Why is this?
Here is some example code:
;main.au3
#include-once
#include "global.au3"
$g1 = "stuff"
$g2 = "stuff"
Run("copy.exe")
;global.au3
#include-once
Global $g1 = ""
Global $g2 = ""
;copy.au3
#include-once
#include "global.au3"
MsgBox(0, $g1, $g2)
main.au3 and copy.au3 have been built into .exe and I double click on main to run it.
The result: $g1 and $g2 are equal to "" and "" when it should be printing "stuff"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
global.au3
未更新。它为您的变量提供初始值。使用#include "global.au3"
与编写相同:并且
如您所见,
copy.au3
(copy.exe
) 有$g1
和$g2
设置为""
。要将
$g1
和$g2
变量传递给copy.exe
,您可以使用IniRead()/IniWrite()< /code> 读取/写入 .ini 文件或将变量作为命令行参数传递。
以下是命令行参数选项的示例:(
不需要 global.au3;
编译main.au3和copy.au3;
双击 main.exe 运行)
main.au3
copy.au3
我使用
ShellExecute()
而不是Run() 因为
Run()
过去(对我来说)一直是 a$$ 中的一个痛苦。我通常对ShellExecute()
和ShellExecuteWait()
没有任何问题。此外,有关命令行参数的更多信息,您可以在 AutoIt 帮助中搜索“命令行参数”。
This is because
global.au3
doesn't get updated. It's providing initial values to your variables. Using#include "global.au3"
is the same as writing:and
As you can see,
copy.au3
(copy.exe
) has$g1
and$g2
set to""
.To pass your
$g1
and$g2
variables tocopy.exe
, you can either useIniRead()/IniWrite()
to read/write an .ini file or pass the variables as command line parameters.Here's an example of the command line parameters option:
(no global.au3 needed;
compile main.au3 and copy.au3;
double click main.exe to run)
main.au3
copy.au3
I used
ShellExecute()
instead ofRun()
becauseRun()
has been a pain in the a$$ in the past (for me). I don't usually have any issues withShellExecute()
andShellExecuteWait()
.Also, for more info on command line parameters you can search on "Command Line Parameters" in the AutoIt help.