void createResourceObject(String name) throws IOException, InterruptedException { ProcessBuilder pb = files.getProcessBuilder().directory(files.resolveTemp(".")); pb.command("ld","-r","-b","binary","-o",name+".o",name); // writes to <name>.o. Symbols are always based on name. Process p = pb.redirectError(files.resolveTemp("ld-"+name+".err")) .redirectOutput(files.resolveTemp("ld-"+name+".out")) .start(); int exit = p.waitFor(); if (exit != 0) { System.err.println(files.loadFromTemp("ld-"+name+".err")); throw KEMException.criticalError("Failed to embed resource into object file. See output for error information."); } }
/** Must be kept compatible with {@link .compileOcamlObject} and consistent with {@link .compileOcaml}. */ void linkOcamlObject(String compiler, String name, String target, String... objectFiles) throws IOException, InterruptedException { // now link ProcessBuilder pb = files.getProcessBuilder(); List<String> args = new ArrayList<>(Arrays.asList( compiler, name, "-o", target, "-Wl,-E")); args.addAll(Arrays.asList(objectFiles)); args.addAll(Arrays.asList("-lmpfr","-lgmp","-lffi","-lm","-ldl")); args.add("-Wl,--no-as-needed"); args.addAll(options.experimental.nativeLibraries); pb.command(args); if (options.global.verbose) { System.err.println("+ " + StringUtils.join(args, " ")); } Process p = pb.redirectError(files.resolveTemp("link.err")) .redirectOutput(files.resolveTemp("link.out")) .start(); int exit = p.waitFor(); if (exit != 0) { System.err.println(files.loadFromTemp("link.err")); throw KEMException.criticalError("Failed to link final program. See output for error information."); } }
public K externalParse(String parser, String value, Sort startSymbol, Source source, CompiledDefinition compiledDef) { List<String> tokens = new ArrayList<>(Arrays.asList(parser.split(" "))); tokens.add(value); Map<String, String> environment = new HashMap<>(); environment.put("KRUN_SORT", startSymbol.toString()); environment.put("KRUN_COMPILED_DEF", files.resolveDefinitionDirectory(".").getAbsolutePath()); RunProcess.ProcessOutput output = RunProcess.execute(environment, files.getProcessBuilder(), tokens.toArray(new String[tokens.size()])); if (output.exitCode != 0) { throw new ParseFailedException(new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, "Parser returned a non-zero exit code: " + output.exitCode + "\nStdout:\n" + new String(output.stdout) + "\nStderr:\n" + new String(output.stderr))); } byte[] kast = output.stdout != null ? output.stdout : new byte[0]; if (BinaryParser.isBinaryKast(kast)) { return BinaryParser.parse(kast); } else { return KoreParser.parse(new String(kast), source); } } }
@Provides ProcessBuilder pb(@WorkingDir File workingDir, @Environment Map<String, String> env) { return new FileUtil(null, null, workingDir, null, null, env).getProcessBuilder(); }
ProcessBuilder pb = files.getProcessBuilder() .command(command); if (workingDir != null) {
/** * Marshals the specified K term using the OCAML Marshal module and returns a string containing the ocaml representation of a string of the resulting bytes. * @param value * @return */ private byte[] marshalValue(K value) { files.saveToTemp("run.in", ToBinary.apply(converter.preprocess(value))); try { Process p = files.getProcessBuilder().command(files.resolveKompiled("marshalvalue").getAbsolutePath(), files.resolveKompiled("realdef.cma").getAbsolutePath()).directory(files.resolveTemp(".")).start(); int exit = p.waitFor(); if (exit != 0) { IOUtils.copy(p.getErrorStream(), System.err); throw KEMException.criticalError("Failed to precompile program variables."); } return FileUtils.readFileToByteArray(files.resolveTemp("run.out")); }catch (IOException e) { throw KEMException.criticalError("Failed to start ocamlopt: " + e.getMessage(), e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw KEMException.criticalError("Ocaml process interrupted.", e); } } }
ProcessBuilder pb = files.getProcessBuilder(); List<String> args = new ArrayList<>(Arrays.asList("-g", "-o", files.resolveTemp("a.out").getAbsolutePath(), "-package", "gmp", "-package", "zarith", "-package", "uuidm", "-package", "str", "-package", "unix", "-package", "dynlink", "-linkpkg", "-safe-string"));
try { for (int i = 0; i < Z3_RESTART_LIMIT; i++) { ProcessBuilder pb = files.getProcessBuilder().command( OS.current().getNativeExecutable("z3"), "-in",
public static Term system(StringToken term, TermContext termContext) { Map<String, String> environment = new HashMap<>(); String[] args = term.stringValue().split("\001", -1); //for (String c : args) { System.out.println(c); } ProcessOutput output = RunProcess.execute(environment, termContext.global().files.getProcessBuilder(), args); KLabelConstant klabel = KLabelConstant.of(KORE.KLabel("#systemResult(_,_,_)"), termContext.definition()); /* String klabelString = "#systemResult(_,_,_)"; KLabelConstant klabel = KLabelConstant.of(klabelString, context); assert def.kLabels().contains(klabel) : "No KLabel in definition for " + klabelString; */ String stdout = output.stdout != null ? new String(output.stdout) : ""; String stderr = output.stderr != null ? new String(output.stderr) : ""; return KItem.of(klabel, KList.concatenate(IntToken.of(output.exitCode), StringToken.of(stdout.trim()), StringToken.of(stderr.trim())), termContext.global()); }
files.saveToKompiled("execution_pgm.ml", execution_pmg_ocaml); ProcessBuilder pb = files.getProcessBuilder(); int exit = pb.command("ocamllex", "lexer.mll").directory(files.resolveKompiled(".")).inheritIO().start().waitFor(); if (exit != 0) {