Applescript 返回“命令以非零状态退出”执行 shell 脚本
我正在使用一个我试图制作的Applescript,在它执行命令后检查命令的结果,但是当我执行它时,它会提示一条消息(在AppleScript编辑器中); 预期的表达,但发现“错误”。
。
如何回退并检查该命令是否与 The command exited with a non-zero status.
相同,以便如果它与错误消息相同,我可以执行其他操作?
do shell script "echo \"stats\" | nc localhost 11211" password "~password~" with administrator privileges
if error = "The command exited with a non-zero status." then
display dialog "Returned zero"
else if result = "The command exited with a non-zero status." then
display dialog "Returned zero"
else if result = "" then
do shell script "memcached -d -l 127.0.0.1 -p 11211 -m 64"
display dialog "Memcached Started"
else
do shell script "killall memcached" with administrator privileges
display dialog "Memcached Stopped"
end if
编辑:更新版本
set error to do shell script "echo \"stats\" | nc localhost 11211" password "~password~" with administrator privileges
if error = "The command exited with a non-zero status." then
do shell script "memcached -d -l 127.0.0.1 -p 11211 -m 64"
display dialog "Memcached Started"
else
do shell script "killall memcached" with administrator privileges
display dialog "Memcached Stopped"
end if
I'm working with an Applescript that I'm trying to make, after it does a command to check back results of a command, but when I execute it, it prompts a message (in AppleScript Editor); Expected expression but found “error”.
.
How can I fallback and check if the command is same as The command exited with a non-zero status.
so I can do something else if it's the same as the error message?
do shell script "echo \"stats\" | nc localhost 11211" password "~password~" with administrator privileges
if error = "The command exited with a non-zero status." then
display dialog "Returned zero"
else if result = "The command exited with a non-zero status." then
display dialog "Returned zero"
else if result = "" then
do shell script "memcached -d -l 127.0.0.1 -p 11211 -m 64"
display dialog "Memcached Started"
else
do shell script "killall memcached" with administrator privileges
display dialog "Memcached Stopped"
end if
EDIT: Updated version
set error to do shell script "echo \"stats\" | nc localhost 11211" password "~password~" with administrator privileges
if error = "The command exited with a non-zero status." then
do shell script "memcached -d -l 127.0.0.1 -p 11211 -m 64"
display dialog "Memcached Started"
else
do shell script "killall memcached" with administrator privileges
display dialog "Memcached Stopped"
end if
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的特殊问题是使用“错误”一词作为变量。 Error 对于 applescript 来说是一个特殊的词,所以它不能用作变量。
但是,即使您解决了该问题,您的代码仍然无法正常工作。您可以使用 try 块捕获错误消息。请注意,“theError”包含错误消息...
Your particular problem is in using the word "error" as a variable. Error is a special word to applescript so it can't be used as a variable.
However, even if you fix that problem your code still won't work properly. You catch error messages with a try block. Note that "theError" contains the error message...