开发者

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

开发者 https://www.devze.com 2023-04-08 09:11 出处:网络
开发者_JAVA技巧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.
开发者_JAVA技巧

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号