使用 Runtime.exec / ProcessBuilder.start 以低优先级启动 Java 进程?
我正在尝试使用 ProcessBuilder 类通过 Java 启动外部进程,这很有效。目前正在使用命令运行:
new ProcessBuilder("java", "-jar", jarfile, args);
我想做的就是这样,但是以低优先级启动进程。我的程序目前仅在 Windows 上运行,因此特定于窗口的解决方案对我来说没问题。一些研究建议我使用“start”命令,但是当我尝试从 Java 执行此操作时,它会给出一个异常,说它是一个无法识别的命令(相同的命令在 cmd.exe 中工作)。
有谁知道如何从 Java 启动一个进程(如果需要的话,特定于 Windows),优先级低于正常值?
I'm trying to start an external process via Java using the ProcessBuilder class, and that much works. Currently running using the command:
new ProcessBuilder("java", "-jar", jarfile, args);
What I would like to do is just this, but to start the process with low priority. My program is currently only running on Windows, so a window-specific solution is fine by me. Some research suggests I use the "start" command, but when I try doing this from Java it gives an exception saying it is an unrecognized command (the same command works from cmd.exe).
Does anyone know how to launch a process from Java (Windows-specific if need be), with belownormal
priority?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用启动命令< /a>.它依赖于 Windows,但可以满足您的需要。我已经读过没有跨平台的方法。
甚至可以读取输入端错误流。
等待:
对于过早销毁:
Use start command. It is windows dependent but does what you need. I have read there is no cross platform way for this.
It is even possible to read Input end Error streams.
To wait:
For premature destroy: