Expiration of an interactive process
You will have to write the input and output records using System.console()
You will need to manually redirect every input to the spawned process and every output to the user.
a source to share
Note. Use this method only when you absolutely need a terminal / console, such as vim. For all other uses, use Runtime.exec ().
I had the same problem. To work, I used Java Native Interface to call a small c function that makes a system call:
SystemProcess.java:
class SystemProcess {
public native int systemCall(String cmd);
public boolean execute() { return systemCall("vim test") == 0; }
static { System.loadLibrary("SystemProcess"); }
}
SystemProcess.c
#include [javah-generated-header.h]
[javah-generated-function-prototype] (JNIEnv *env, jobject obj, jstring jcmd) {
jboolean iscopy;
const char *cmd = (*env)->GetStringUTFChars(env, jcmd, &iscopy);
jint ec = system(cmd);
(*env)->ReleaseStringUTFChars(env, jcmd, cmd);
return ec;
}
I'll leave it all to actually do all the header generation and c compilation into a shared library. Feel free to replace the fork / exec or posix_spawn system if you get better. But for the most part it should work like on unix / linux.
a source to share
In 1.7 it's pretty straight forward. (Of course everything when you've solved it before)
ProcessBuilder builder = new ProcessBuilder("/usr/bin/vim");
Map<String, String> environ = builder.environment();
builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
final Process process = builder.start();
process.waitFor();
a source to share