JAVA-使一个程序与另一个程序交互 [英] JAVA - make one program interact with another

查看:116
本文介绍了JAVA-使一个程序与另一个程序交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何使不同的程序彼此交互,但是对我而言,在线查找有关此的信息是不可能的.我是一位自学的Flash/PHP程序员,最近学习了基本的Java.

I'm trying to learn how to make different programs interact with each other, but finding information online on that has been impossible for me. I'm a self taught Flash/PHP programmer who has learned basic java recently.

让我们假设有一个用Java编写的游戏,并且我可以访问它的开源.如果要为其显示每秒帧数",现在就可以以我目前的知识轻松地做到这一点.我将打开Eclipse,检查代码,找到在哪里正确放置FPS计数器,重新编译游戏并使用新的重新编译版本.

Let´s assume there is a game coded in Java, and I have access to its open source. If I wanted to make a Frames Per Second display for it, I could easily do that now with my current knowledge. I'd open Eclipse, examine the code and find where to properly place the FPS counter, recompile the game and play with the new recompiled version.

那不是我现在想要学习的东西.我要做的是制作一个独立的.exe或.jar文件,当我运行它时,它将在游戏中显示FPS,而无需我重新编译它.我们看到人们一直在这样做.我现在正在玩一个带有一个可打开.exe文件的mod的新维加斯文件,该文件在游戏中显示叠加图.

That is not what I'm trying to learn now though. What I want to do is make a standalone .exe or .jar file that when I run it, it will display FPS in the game without me recompiling it. We see people doing that all the time. I'm playing new vegas now with a mod that opens an .exe file that displays an overlay map in the game.

但是,我不知道如何实现这样的目标.这些程序背后的逻辑到底是什么?我应该读哪个主题以了解该怎么做?

However, I have no idea how to achieve something like that. What exactly is the logic behind such programs? What topic should I be reading to understand how to do that?

如果FPS示例过于复杂,我将尝试一个更简单的示例.我有一个可以打印Hello World的程序.我想制作另一个将运行Hello World的程序,但是将字符串更改为其他名称.再说一次,我什至不知道从哪里开始.

If the FPS example is too complex, I'll try a simpler one. I have a program that prints Hello World. I'd like to make another program that will run Hello World, but change the string to something else. Again, I don't even know where to begin.

谢谢

推荐答案

您正在寻找的搜索关键字是"IPC"(进程间通信).有许多解决方案,请参见此处和<在href ="https://www.google.com/search?q=java+interprocess+communication" rel ="nofollow noreferrer">此处.

The search keyword you are looking for is "IPC" (Inter-Process Communications). There are many solutions, see here and here for some starting points.

大多数解决方案都涉及以下一种或多种形式:

Most solutions involve some form of one or more of the following:

  • 套接字
  • 共享内存
  • 命名管道(在支持它的平台上)
  • 将数据存储在文件/数据库中
  • 其他自动化(例如Windows上的OLE,工具包自动化等)
  • 更多...

在您的情况下,基于基本网络套接字的解决方案非常简单(您的游戏运行基本服务器,监控应用程序连接并定期查询游戏提供的帧速率;这允许本地和远程监控,并且涉及相当少量的代码).在 Java进程间通信中有一些相关的搜索起点.

In your case a basic network socket based solution would be very straightforward (your game runs a basic server, your monitor application connects and periodically queries the frame rate, which your game provides; this allows both local and remote monitoring and involves a fairly minimal amount of code). There is some related search starting points at Java Interprocess Communication.

对于您的特定"hello world"示例,实际上是另一种情况.这可以简单地通过使打印程序采用指定字符串的命令行参数,然后使调用程序以适当的命令行参数执行来实现.

For your specific "hello world" example, that's actually a different case. That could be accomplished simply by having the printing program take a command line parameter that specified the string, and having the calling program execute it with appropriate command line parameters.

这篇关于JAVA-使一个程序与另一个程序交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆