Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AppleScript强制退出Java(JAR)程序?_Java_Macos_Process_Applescript_Activity Monitor - Fatal编程技术网

AppleScript强制退出Java(JAR)程序?

AppleScript强制退出Java(JAR)程序?,java,macos,process,applescript,activity-monitor,Java,Macos,Process,Applescript,Activity Monitor,你好, 我在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 | a

你好,

我在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)
当我运行“NPC.app”时,运行Java程序的AppleScript称为“NPC.app”,它在活动监视器应用程序上显示为NPCNPC.NPC。设置为删除NPC应用程序的上述代码不会删除NPC(这是“NPC.app”)或NPC.NPC(这是Java程序)。我得到以下错误

错误“sh:line 0:kill:1180 1182:参数必须是进程或作业 IDs“1号

1180是活动监视器中NPC的PID,1182是NPC.NPC的PID


强制退出Java程序的正确AppleScript是什么?

尝试使用
pkill

do shell script ("pkill -9 NPC*")

一些示例。

下面是将关闭Java程序的AppleScript

tell application "Terminal"
    do shell script "ps ax | grep \"java.*$1\" | grep -v grep | awk '{ print \"kill \" $1 }' | sh"
    quit
end tell
*参考:


感谢:wojciechka♦♦*

谢谢你的帮助。但我在尝试时出现了以下错误消息:“命令以非零状态退出。”第1条如果您尝试从终端窗口手动运行它,会发生什么?另外,试试不同的信号号码。谢谢马克。我还在努力。但我会在一两天内回复你。无论谁否决了我的回复,如果你能有礼貌地解释为什么…不是我,马克,那就太好了。我仍在用我的程序编写脚本。