数据未保存在 autoit 中

发布于 2024-10-11 21:41:22 字数 520 浏览 2 评论 0原文

我正在使用一个文件将数据发送到全局文件中的全局变量,然后让另一个文件尝试从全局文件中检索该数据。

示例:

主文件将数据发送到全局文件,其他文件从全局文件获取数据

由于某种原因,数据没有被保留。当我从全局文件中提取数据时,它不在那里。这是为什么呢?

下面是一些示例代码:

;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必你懂 2024-10-18 21:41:22

这是因为 global.au3 未更新。它为您的变量提供初始值。使用 #include "global.au3" 与编写相同:

;main.au3
#include-once
Global $g1 = ""
Global $g2 = ""

$g1 = "stuff"
$g2 = "stuff"

Run("copy.exe")

并且

;copy.au3
#include-once
Global $g1 = ""
Global $g2 = ""

MsgBox(0, $g1, $g2)

如您所见,copy.au3 (copy.exe) 有$g1$g2 设置为 ""

要将 $g1$g2 变量传递给 copy.exe,您可以使用 IniRead()/IniWrite()< /code> 读取/写入 .ini 文件或将变量作为命令行参数传递。

以下是命令行参数选项的示例:(

不需要 global.au3;
编译main.au3和copy.au3;
双击 main.exe 运行)

ma​​in.au3

;main.au3

$g1 = "stuff"
$g2 = "stuff"

ShellExecute('copy.exe', $g1 & ' ' & $g2)

copy.au3

;copy.au3

$g1 = $CmdLine[1]
$g2 = $CmdLine[2]

MsgBox(0, $g1, $g2)

我使用 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:

;main.au3
#include-once
Global $g1 = ""
Global $g2 = ""

$g1 = "stuff"
$g2 = "stuff"

Run("copy.exe")

and

;copy.au3
#include-once
Global $g1 = ""
Global $g2 = ""

MsgBox(0, $g1, $g2)

As you can see, copy.au3 (copy.exe) has $g1 and $g2 set to "".

To pass your $g1 and $g2 variables to copy.exe, you can either use IniRead()/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

;main.au3

$g1 = "stuff"
$g2 = "stuff"

ShellExecute('copy.exe', $g1 & ' ' & $g2)

copy.au3

;copy.au3

$g1 = $CmdLine[1]
$g2 = $CmdLine[2]

MsgBox(0, $g1, $g2)

I used ShellExecute() instead of Run() because Run() has been a pain in the a$$ in the past (for me). I don't usually have any issues with ShellExecute() and ShellExecuteWait().

Also, for more info on command line parameters you can search on "Command Line Parameters" in the AutoIt help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文