我可以在用户按 Control-C 后强制 MATLAB 退出吗?
我正在从 shell 脚本运行 MATLAB(命令行版本),并且我希望它能够保留 shell 行为,如果您按 Ctrl-C 它就会退出。但相反,它想要保持对终端的控制,而我(或我之后的可怜的用户)必须输入 quit(1)
才能使其退出并告诉 shell 它失败了。
你不能用 try
/catch
块拦截 Ctrl-C ...还有其他想法吗?我可以从 shell 端做些什么来在击键到达 MATLAB 之前拦截它们吗?
onCleanup
似乎是一个选项,但是我必须将整个脚本变成一个函数(它已经是动态生成的 try
/catch
在 Makefile 中阻止事物)。但如果这是唯一可行的办法,那么我就会这么做……
I'm running MATLAB (command line version) from a shell script, and I'd like it to preserve shell behavior where if you press Ctrl-C it exits. But instead it wants to keep control of the terminal and I (or my poor users after me) have to type quit(1)
to make it quit and tell the shell it failed.
You can't intercept Ctrl-C with a try
/catch
block... any other ideas? Anything I could do from the shell side to intercept the keystrokes before they get to MATLAB?
onCleanup
seems like an option, but then I'd have to make the whole script thing into a function (it's already a dynamically generated try
/catch
block thing in a Makefile). But if that's the only thing that will work, then I'll do it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
onCleanup
:我想做同样的事情,但在阅读 此线程 我使用了 onCleanup 成功。我的问题是我在 Matlab 中有一个服务器,当按 CTRL+C 时,它会继续监听它启动的端口 ->第二次运行时,我会收到
bind
错误。Use
onCleanup
:I wanted to do the same thing but after I read this thread I used onCleanup successfully. My problem was I had a server in Matlab that when pressing CTRL+C would keep
listen
ing on the port it was started on -> second run I would get abind
error.你可以试试:
但是我没有matlab来测试它。
You can try:
but I have no matlab to test it.