尝试访问由 Java 程序启动的(服务器)程序时出现权限错误

发布于 2024-08-30 11:52:13 字数 366 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-09-06 11:52:13

我猜测您的服务器程序正在尝试写入标准输出或标准错误(Java 术语中的 System.out / System.err ),它隐式地从您的继承Java 程序,但是当你的 Java 程序消失时,它就会变成南瓜。

一个简单的解决方案可能是让您的 Java 程序执行一个 shell 脚本,该脚本将您的服务器作为后台进程启动(使用 START (Windows) 或 & (Unix)) 具有显式重定向的 I/O 流。

Java 库最近对 Process 类进行了一些不错的更新(我认为),允许您对流进行大量摆弄,但我在那里没有太多经验,所以我可以'不提供详细的建议。


编辑:我从中间段落中提出的建议。未经测试,抱歉!

文件server-runner.sh

#!/bin/bash
/path/mmserver >/dev/null &

当然,您需要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 (using START (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:

#!/bin/bash
/path/mmserver >/dev/null &

You'll need to chmod +x server-runner.sh, of course.

Then, from your Java program, you exec the script server-runner.sh rather than your mmserver.

If you want to kill mmserver, you'll have to find it in ps -ux and use kill on the process number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文