简体   繁体   中英

How to execute a windows executable remotely from a java server?

I want to execute a program on a windows machine from a java program that is running on a java server in another windows machine and return something from that executable.

While I am researching different ways to do this, I don't seem to find any popular approach.

What would be a quick but standard way of accomplishing this distributed call?

(RPC, CORBA, Sockets??)

Thanks

If both machines run in a trusted LAN environment, then sockets should do the trick. Java has very convenient socket classes built in so it'll be very straightforward to implement.

On the executor you'll have to create a ServerSocket . Then, in a loop, accept() a connecting socket, run your program, write data to the socket's output stream and close it.

On the connecting side you'll just create a new Socket , read the data from the socket's input stream and close it.

If you want to service multiple requests concurrently then it's slightly less straightforward but still quite easy if you know how to program threads.

Ok if you can't run java on the other machine I'd locally call a .NET application that does the RPC to another .NET application on the other machine. In this case you can use .NET Remoting or WCF (or DCOM if you are forced to).

As another option you could stick to Sockets on both Java and .NET side. (I am sure .NET also has a Socket implementation)

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