尝试访问由 Java 程序启动的(服务器)程序时出现权限错误
我正在使用 Runtime.getRuntime().exec("path/mmserver") 启动服务器应用程序(通常从 Unix 命令行启动)。我现在的问题是,只要启动该服务器的 Java 程序运行,就可以正确访问该服务器(从命令行和其他程序)。但是当我的Java程序退出时,服务器将无法再访问(服务器的进程仍在运行)。我在尝试访问服务器时收到这样的错误消息:“错误:permission_error(flush_output(user_output),write,stream,user_output,errno(32))”。 服务器对我来说是一个黑匣子。
我只是在寻找其他方法来开始新的流程。也许有人暗示我为什么会收到该权限错误(即使有人不知道该服务器到底是什么......您宁愿不知道它)。
I am starting a server application (normally to be started from the Unix command line) by using Runtime.getRuntime().exec("path/mmserver"). My problem is now that as long as my Java program, which started that server runs, the server is correctly accessible (from command line and other programs). But when my Java program exits the sever is not accessible anymore (the process of the server is still running). I just get such a error message when trying to access the server: "Error: permission_error(flush_output(user_output),write,stream,user_output,errno(32))".
The server is a blackbox for me.
I am just looking for other ways to start a new process. And maybe someone has a hint why I get that permission error (even if one doesn't know what that server exactly is ... you rather won't know it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测您的服务器程序正在尝试写入标准输出或标准错误(Java 术语中的
System.out
/System.err
),它隐式地从您的继承Java 程序,但是当你的 Java 程序消失时,它就会变成南瓜。一个简单的解决方案可能是让您的 Java 程序
执行
一个 shell 脚本,该脚本将您的服务器作为后台进程启动(使用START
(Windows) 或& (Unix)) 具有显式重定向的 I/O 流。
Java 库最近对
Process
类进行了一些不错的更新(我认为),允许您对流进行大量摆弄,但我在那里没有太多经验,所以我可以'不提供详细的建议。编辑:我从中间段落中提出的建议。未经测试,抱歉!
文件
server-runner.sh
:当然,您需要
chmod +x server-runner.sh
。然后,从 Java 程序中,
exec
脚本server-runner.sh
而不是mmserver
。如果您想终止 mmserver,则必须在
ps -ux
中找到它,并对进程号使用kill
。I'm guessing your server program is trying to write to standard output or perhaps standard error (
System.out
/System.err
in Java terms) which it implicitly inherited from your Java program but which turn into pumpkins when your Java program goes away.A simple solution might be for your Java program to
exec
a shell script which starts your server as a background process (usingSTART
(Windows) or&
(Unix)) with explicitly redirected I/O streams.The Java library has recently gotten some nice updates to the
Process
class (I think) that allow you to do a lot of fiddling with the streams, but I don't have much experience there so I can't offer a detailed suggestion.EDIT: My suggestion from the middle paragraph. Untested, sorry!
File
server-runner.sh
:You'll need to
chmod +x server-runner.sh
, of course.Then, from your Java program, you
exec
the scriptserver-runner.sh
rather than yourmmserver
.If you want to kill mmserver, you'll have to find it in
ps -ux
and usekill
on the process number.