简体   繁体   中英

How to Read/Write to a Process in Java

I'm trying to gain access to a running process that I know the name of so that I can read and write to it.

How can this be done in Java?

There are many ways. What you need isn't clear enough to know which one is suitable for your need.

  1. You could launch the JVM with debugging flags, allowing you to attach a debugger (gaining read and write access to the internals of your running program).
  2. You could read and write to and from the standard input, standard output and standard error streams, launching the program with those streams redirected to other programs or pipes.
  3. You could open a socket and do network communications between one program acting as a client and another acting as a server (peer-to-peer is just were all client programs act as servers too).
  4. You could communicate through a third-party item, like a message queue, a data base entry (bad idea, but we've all seen it), a file on disk (again bad idea), a shared memory buffer, a name pipe, a shared semaphore etc.

Unfortunately the details of each possibility are too great to post in such an answer; and, would probably be noise if they don't match well with your communication goals. I suggest you alternate between reading up on some of these technologies and thinking about what style and requirements you have for communication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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