你好,
我在 MAC OS 上运行 Java (jar) 应用程序。我正在使用 AppleScript 运行 Java 程序,它运行良好。现在,我喜欢使用 AppleScript 来关闭 Java 程序。我需要强制退出Java 程序。我使用了以下 AppleScript,
set app_name to "NPC"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)
运行 Java 程序的 AppleScript 称为“NPC.app” 当我运行“NPC.app”时,它在 Activity Monitor 应用程序上显示为NPC和NPC.npc 。上面设置为删除 NPC 应用程序的代码不会删除NPC(这是“NPC.app”)或NPC.npc(这是 Java 程序)。我收到以下错误,
错误“sh: line 0: kill: 1180 1182: arguments must be process or job IDs” number 1
1180 是NPC的 PID ,1182 是Activity Monitor中NPC.npc的 PID。
强制退出 Java 程序的正确 AppleScript 是什么?