gpt4 book ai didi

shell - 执行shell脚本后退出applescript应用程序

转载 作者:行者123 更新时间:2023-12-05 01:25:44 25 4
gpt4 key购买 nike

我想知道 Applescript 应用程序是否可以运行 shell 脚本,然后在 shell 脚本的执行完成之前退出。在给定的时间内运行服务器时,这将非常有用。有没有办法独立运行一个函数,而不是需要在后台不断运行applescript?

set server_name to text returned of (display dialog "Choose server." default answer "")
set success to do shell script "if [ -f \"/Users/jessefrohlich/Documents/Minecraft/" & server_name & "/minecraft_server.jar\" ]; then
echo 1;
else
echo 0;
fi"
if success is equal to "1" then
do shell script "cd /Users/jessefrohlich/Documents/Minecraft/" & server_name & "
java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
else
display dialog "Sorry, the file you chose is invalid."
end if

当上述作为应用程序运行时,它将正确启动服务器。但是,申请 runScript.app将继续运行。即使applescript 被强制退出,服务器也会继续运行。有没有办法让它在服务器启动后自动退出?

谢谢

最佳答案

尝试这个。祝你好运。

-- "> /dev/null" redirects standout out to nowhere land
-- - you can use some other file path if you want to capture its output
-- "2>&1" redirects standard error to the same place as standard out
-- - 2 stands for standard error
-- - 1 stands for standard out
-- - > is the redirect symbol
-- - & changes redirect's output from a file to a file descriptor (in this case standard out)
-- & the trailing & sends the process to the background

do shell script "cd /Users/jessefrohlich/Documents/Minecraft/" & server_name & " java -Xmx1024M -Xms1024M -jar minecraft_server.jar > /dev/null 2>&1 &"

关于shell - 执行shell脚本后退出applescript应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11285877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com