有没有办法在 autoit 脚本中找到当前文件是否被包含或它自己运行? [英] is there a way in autoit script to find if current file was included or it is running on its own?
问题描述
我的意思是类似于 php 中的 get_included_files();
或 javascript 中的 Error().stack;
或 bash 中的 $BASH_SOURCE
数组?
I mean something like get_included_files();
in php or Error().stack;
in javascript or $BASH_SOURCE
array in bash ?
我只在宏中找到( https://www.autoitscript.com/autoit3/docs/macros.htm ) @ScriptFullPath
和 @ScriptName
.
I've only found in macros ( https://www.autoitscript.com/autoit3/docs/macros.htm ) @ScriptFullPath
and @ScriptName
.
推荐答案
是的,有办法.检查@ScriptName 是否与当前脚本的名称匹配.如果不是,则您的脚本已包含在其他内容中.如果包含的脚本作为独立脚本运行,我将使用此方法运行单元测试.我将以下代码添加到included_script.au3的末尾...
Yes there is a way. Check if @ScriptName matches the name of the current script. If it doesn't your script has been included in something else. I use this method to run a unit test if an included script is run as a stand alone script. I add the following code to the end of included_script.au3...
; unit test code
if @ScriptName == "included_script.au3" Then
MsgBox(0,"Unit Test","Running unit test...",3)
test()
exit
endif
func test()
; no test defined
EndFunc
当包含在main.au3"文件中时,@ScriptName 将被设置为main.au3"并且它不会运行 test()
When included in a "main.au3" file, the @ScriptName will be set to "main.au3" and it will not run test()
这篇关于有没有办法在 autoit 脚本中找到当前文件是否被包含或它自己运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!