Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I launch Unix application from Windows

Status
Not open for further replies.

martindavey

Programmer
Jan 2, 2000
122
0
0
GB
Hi,

I have a Java Application that serves as a GUI frontend to a C application on a Unix box.

FYI. The Unix filesystem is visible on the Windows network thanks to Samba.

I want to launch a C executable on the Unix box when the user clicks on a button in the Windows based Java App.

I would then want the Java App. to be able to determine when the C application has finished executing.

Any help would be greatly appreciated.
 
Process p = Runtime.getRuntime().exec("s:/a/b/c/program");
p.waitFor();

where s: is your samba mount.
 
Hi sedj,

Many thanks for your reply.

I get the following runtime error:-

java.io.IOException: CreateProcess: z:/a/b/c/loginTest error=3

My code is as follows:-
Process ls_proc = Runtime.getRuntime().exec("z:/a/b/c/loginTest");

I've mapped z: to our samba share.

Any ideas?
 
Are you sure z:/a/b/c/loginTest exists ?

If it does try :


Process ls_proc = Runtime.getRuntime().exec(new String[]{"z:/a/b/c/loginTest"});

or

Process ls_proc = Runtime.getRuntime().exec(new String[]{"sh", "z:/a/b/c/loginTest"});

(where "sh" is your linux/unix shell type)

 
This is a really interseting post.

If you have a Samba mounted unit on Windows, can you run any Unix shell scripts by simply doing and exec call?

Or do you need to configure any more options? I mean, the Samba just mounts a filesystem or also loads the OS features?

Thanks

Dian
 
Crikey, I'm going mad, and do apologise.

Of course it won't work, as while it can see the UNIX FS, it still executes on the Windows box. Dumbass me.

So, your options are, using a distributed architecture such as RMI, XML-RPC and such.

 
That's much better. I couldn't imagine a world where people with different operative systems could happily understand each other. I'd loose my job :p

Now seriously, maybe another way of doing that is using an shell emulator for windows, and make it the target of the exec command.

Something like:

Process ls_proc = Runtime.getRuntime().exec(new String[]{"Some Shell Emulator", "z:/a/b/c/loginTest"});

But to be sincere, I'm not totally sure. It will depend on the nature and purpose of the script. It will perform a "ls -a | grep 'file'" but I guess it will fail with more complicated tasks.

Cheers.

Dian



 
Thanks guys.

We have our Ent. App. Server running on the Unix box, and the EJBs are going to be deployed there - so I suppose I could write an EJB that performs the exec() call and invoike that using RMI from the Client App.

 
If I understand the problem right, the client shall start an application on the server.
The server shall inform the client, after the application had finished.

I can Imagine different solutions.
One would be, to use rpc (remote proceduere calls); I didn't use it intensively, so I recommend reading some manuals.

Another solution would be to use sockets. Your clients would send messages to the server (define your own port for that, bigger than 1024), which waits for such messages, and calls the corresponding program (with the Runtime.exec (...)) methods, but of course on the server.
After finishing it's command he may respond via the socket (finished, error, ...) and the clients may react on the response.

There are plenty of good and easy descriptions on how to use sockets in the net too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top