简体   繁体   English

在C#NET中运行Java应用程序

[英]Running Java Application in C# NET

I wrote an application a while ago in C# NET that basically allows the .exe I created to start/stop when the java application (Minecraft) starts and stops. 不久前,我在C#NET中编写了一个应用程序,该应用程序基本上允许我创建的.exe在Java应用程序(Minecraft)启动和停止时启动/停止。

I would like to extend some more functionality to my application by basically allowing users to type commands into my console app, and in turn send these commands to the .jar file that is running. 我想通过基本允许用户在控制台应用程序中键入命令,然后将这些命令发送到正在运行的.jar文件,来为我的应用程序扩展一些功能。

I read something a while ago on stackoverflow that said there were some APIs that would basically let you manage Java apps inside of a C# NET app but I can't find it now. 不久前,我在stackoverflow上读到一些内容,其中说有一些API基本上可以让您在C#NET应用程序内部管理Java应用程序,但现在找不到。

Does anyone know how I could go about doing this? 有人知道我该怎么做吗?

如果使用Process类从C#启动和管理Java应用,则可以通过Process.StandardInput将输入从C#应用发送到已启动的Java应用进程。

Minecraft accepts commands from system in and responds to system out. Minecraft接受来自系统输入的命令并响应系统输出。

When you start minecraft from your application you basicly creates a new process. 从应用程序启动minecraft时,基本上会创建一个新过程。 This process has two streams, one for system out and one for system in. You need to get hold of those streams. 此过程有两个流,一个用于系统输出,一个用于系统输入。您需要掌握这些流。 If you send characters to the system in stream, then they will be interpreted as commands to minecraft. 如果您在流中向系统发送字符,那么它们将被解释为对我的世界的命令。 If you read from the system out stream then you will get minecrafts response. 如果您从系统中读取信息,那么您将获得《我的世界》响应。

Your next task would be to let your users send commands to minecraft. 您的下一个任务是让您的用户将命令发送到Minecraft。 One way to do this would be to let your users type in commands on a web page that you store in a file. 一种方法是让您的用户在您存储在文件中的网页上键入命令。 You could have a separate thread read from the file and write the commands to minecraft's system in stream. 您可以从文件中读取一个单独的线程,然后将命令以流的形式写入Minecraft的系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM