use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BasePythonTest method execModule.
public String execModule(String fileName) {
String pythonPath = locatePython();
String runtimePath = locateRuntime();
File tmpdirFile = new File(getTempDirPath());
String modulePath = new File(tmpdirFile, fileName).getAbsolutePath();
String inputPath = new File(tmpdirFile, "input").getAbsolutePath();
Path outputPath = tmpdirFile.toPath().resolve("output").toAbsolutePath();
try {
ProcessBuilder builder = new ProcessBuilder(pythonPath, modulePath, inputPath, outputPath.toString());
builder.environment().put("PYTHONPATH", runtimePath);
builder.environment().put("PYTHONIOENCODING", "utf-8");
builder.directory(tmpdirFile);
Process process = builder.start();
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
stderrVacuum.start();
process.waitFor();
stderrVacuum.join();
String output = TestOutputReading.read(outputPath);
if (stderrVacuum.toString().length() > 0) {
setParseErrors(stderrVacuum.toString());
}
return output;
} catch (Exception e) {
System.err.println("can't exec recognizer");
e.printStackTrace(System.err);
}
return null;
}
Aggregations