views:

40

answers:

1

I am starting a server application (normally to be started from the Unix command line) by using Runtime.getRuntime().exec("path/mmserver"). My problem is now that as long as my Java program, which started that server runs, the server is correctly accessible (from command line and other programs). But when my Java program exits the sever is not accessible anymore (the process of the server is still running). I just get such a error message when trying to access the server: "Error: permission_error(flush_output(user_output),write,stream,user_output,errno(32))". The server is a blackbox for me.

I am just looking for other ways to start a new process. And maybe someone has a hint why I get that permission error (even if one doesn't know what that server exactly is ... you rather won't know it).

A: 

I'm guessing your server program is trying to write to standard output or perhaps standard error (System.out / System.err in Java terms) which it implicitly inherited from your Java program but which turn into pumpkins when your Java program goes away.

A simple solution might be for your Java program to exec a shell script which starts your server as a background process (using START (Windows) or & (Unix)) with explicitly redirected I/O streams.

The Java library has recently gotten some nice updates to the Process class (I think) that allow you to do a lot of fiddling with the streams, but I don't have much experience there so I can't offer a detailed suggestion.


EDIT: My suggestion from the middle paragraph. Untested, sorry!

File server-runner.sh:

#!/bin/bash
/path/mmserver >/dev/null &

You'll need to chmod +x server-runner.sh, of course.

Then, from your Java program, you exec the script server-runner.sh rather than your mmserver.

If you want to kill mmserver, you'll have to find it in ps -ux and use kill on the process number.

Carl Smotricz
"turn into pumpkins" <-- Is there a command-line switch to prevent this? Like `-Xcinderella=0`
R. Bemrose
I usually try to stay away from culture-specific in-jokes, but in this case I couldn't resist, and I'm hoping the poster will be able to extrapolate my meaning. If not, he should think of pumpkins as very large values of `null` ;)
Carl Smotricz
@Carl: I tried a Runtime.getRuntime().exec("bash path/mmserver -)). When I start the server from the command line, the call does not return (it constantly prints to the command line). To stop the server I use ctrl+c on the command line. So I guess your estimations about the streams are right. Any suggestions what else I could try?
Zardoz
@Zardoz: I've edited my post to explicitly demonstrate the shell script I had in mind. See how that goes!
Carl Smotricz
@Carl: Still no luck ... the problem remains. I still wonder what the Java exec does different than I do on console (especially after your adjustment).
Zardoz
I don't seem to be helping you. I suggest you fire up a new question here in hopes of attracting a more useful answer!
Carl Smotricz