Skip to content

Instantly share code, notes, and snippets.

@valich
Last active March 28, 2016 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valich/e6c2c8d7d0d521bc9808 to your computer and use it in GitHub Desktop.
Save valich/e6c2c8d7d0d521bc9808 to your computer and use it in GitHub Desktop.
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
import gnu.trove.THashMap;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by Valentin.Fondaratov on 3/28/2016.
*/
public class Test {
public static void main(String[] args) throws IOException, InterruptedException {
final String[] commands = new String[]{
"C:\\jruby-9.0.5.0\\bin\\jruby.exe",
"-e",
"$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)",
"C:/jruby-9.0.5.0/bin/jirb",
"--prompt",
"simple"
};
final String envblock = ""; // I've erased this, there should be some envs
THashMap<String, String> envVars = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
for (String kv : envblock.split("\u0000")) {
int eq = kv.indexOf('=');
if (eq != -1) {
envVars.put(kv.substring(0, eq), kv.substring(eq + 1));
}
}
ProcessBuilder builder = new ProcessBuilder(commands);
builder.environment().putAll(envVars);
builder.directory(new File("C:\\"));
//builder.inheritIO();
builder.redirectErrorStream(false);
builder.redirectError(ProcessBuilder.Redirect.PIPE);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
Process process = builder.start();
try (BufferedReader in =new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String s;
while ((s = in.readLine()) != null) {
System.out.println(s);
}
}
System.exit(process.waitFor());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment