PackageMaker“脚本结果"需求永不超越 [英] PackageMaker "Result of Script" requirement never passes
问题描述
我正在尝试使用脚本结果"检查特定进程是否正在运行的要求,以便我可以在安装开始之前向用户发送消息. 我的脚本是一个shell脚本,如果失败,则返回1,如果成功,则返回0.我遇到的问题是,无论返回值如何,安装程序流程都将其解释为失败.我没有使用非常简单的脚本:
I am trying to use the "Result of Script" Requirement to check if a particular process is running, so that I can message the user before installation begins. My script is a shell script that returns 1 for failure and 0 for success. The problem I'm having is that, regardless of my return value, the installer flow is interpreting it as failure. I am not using an incredibly simple script:
#!/bin/bash
echo "script starting">> /tmp/myfile
true
(回声是为了向自己保证脚本实际上正在运行).我尝试用很多东西(出口0,出口1,"true","TRUE")替换最后一行,但没有任何结果导致测试通过.
(the echo is to assure myself that the script is, in fact, running). I've tried replacing the last line with a lot of things (exit 0, exit 1, "true", "TRUE") but nothing results in the test passing.
我还发现了以下JavaScript代码,当我激活此要求时,这些代码会添加到distribution.dist中.
I also discovered the following JavaScript code that gets added to distribution.dist when I activate this requirement.
<installation-check script="pm_install_check();"/>
<script>function pm_install_check() {
if(!(system.run('path/to/script/myscript.sh') == true)) {
my.result.title = 'Title';
my.result.message = 'Message';
my.result.type = 'Fatal';
return false;
}
return true;
}
</script>
据我所知,
if语句中的表达式永远不会评估为true.所以,我假设这是我的问题.不过,我不知道如何解决它,因为此代码是由PackageMaker生成的.
as far as i can tell, the expression in the if statement will never evaluate to true. So, I'm assuming this is my problem. I don't know how to get around it, though, because this code is generated by PackageMaker.
我已经决定在这种印象下工作,这是PackageMaker中的错误,并且已经接近解决方法.而不是使用脚本结果",要求,我使用了"Java脚本的结果"要求,并构建了一个Javascript函数,如下所示:
I've decided to work under the impression that this is a bug in PackageMaker, and am close to a workaround. Rather than using the "Result of Script" requirement, I used the "Result of Javascript" requirement, and built a Javascript function the looks like
function my_check() {
code = system.run('path/to/script/myscript.sh');
return code == 0;
}
现在,我唯一的问题是,这仅在我通过绝对路径指向脚本时才有效.显然,这给安装程序带来了麻烦.
Now my only problem is that this will only work when I point to my script via an absolute path. Obviously this poses a problem for an installer.
推荐答案
对您来说可能为时已晚,但我认为应该在某处进行记录.
It's probably too late for you but I feel like this should be documented somewhere.
今天上午大部分时间,我一直在寻找答案.长话短说,我结束了对通用bash脚本的研究,发现了一些有关从脚本调用的脚本返回值的信息.这是可以完成的方法:
I'd been looking around for an answer for this for most of this morning. Long story short I ended up looking at generic bash scripting and I found some info about returning values from a script called by a script. Here's how it can be done:
在要使用exit 0
的任何地方(成功使用),请使用$(exit 1)
.
Anywhere you'd be using exit 0
(for success) use $(exit 1)
.
如您所料,应将exit 1
替换为$(exit 0)
.
As you'd expect exit 1
should be replaced by $(exit 0)
.
我意识到它是倒退的,我并没有真正了解其背后的原因,但是经过一些试验之后,我才发现了这一点.
I realize that it's backwards and I don't really get the reasoning behind it but after some experimentation that's what I found.
这篇关于PackageMaker“脚本结果"需求永不超越的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!