public static boolean testCommand( final Context context, final String command, final String contains, final List<String> arguments) { try { final List<String> commandAndArgs = new ArrayList<String>(); commandAndArgs.add(command); commandAndArgs.addAll(arguments); final ProcessBuilder pb = new ProcessBuilder(commandAndArgs); logCommand(context, pb); final Process compilation = pb.start(); final ConsumeStream result = ConsumeStream.start(compilation.getInputStream(), null); final ConsumeStream error = ConsumeStream.start(compilation.getErrorStream(), null); compilation.waitFor(); result.join(); error.join(); return error.output.toString().contains(contains) || result.output.toString().contains(contains); } catch (IOException ex) { context.log(ex.getMessage()); return false; } catch (InterruptedException ex) { context.log(ex.getMessage()); return false; } }
private void setExecutablePermissions(File gradleHome) { if (isWindows()) { return; } File gradleCommand = new File(gradleHome, "bin/gradle"); String errorMessage = null; try { ProcessBuilder pb = new ProcessBuilder("chmod", "755", gradleCommand.getCanonicalPath()); Process p = pb.start(); if (p.waitFor() == 0) { System.out.println("Set executable permissions for: " + gradleCommand.getAbsolutePath()); } else { BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); Formatter stdout = new Formatter(); String line; while ((line = is.readLine()) != null) { stdout.format("%s%n", line); } errorMessage = stdout.toString(); } } catch (IOException e) { errorMessage = e.getMessage(); } catch (InterruptedException e) { errorMessage = e.getMessage(); } if (errorMessage != null) { System.out.println( "Could not set executable permissions for: " + gradleCommand.getAbsolutePath()); System.out.println("Please do this manually if you want to use the Gradle UI."); } }
private static void exec(String command) { try { System.out.println("Invoking: " + command); Process p = Runtime.getRuntime().exec(command); // get standard output BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); // get error output input = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); p.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
public String execRecognizer() { try { String inputFile = new File(tmpdir, "input").getAbsolutePath(); String[] args = new String[] {"java", "-classpath", tmpdir + pathSep + CLASSPATH, "Test", inputFile}; // String cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir, // "input").getAbsolutePath(); // System.out.println("execParser: "+cmdLine); Process process = Runtime.getRuntime().exec(args, null, new File(tmpdir)); StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream()); StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream()); stdoutVacuum.start(); stderrVacuum.start(); process.waitFor(); stdoutVacuum.join(); stderrVacuum.join(); String output = null; output = stdoutVacuum.toString(); if (stderrVacuum.toString().length() > 0) { this.stderrDuringParse = stderrVacuum.toString(); System.err.println("exec stderrVacuum: " + stderrVacuum); } return output; } catch (Exception e) { System.err.println("can't exec recognizer"); e.printStackTrace(System.err); } return null; }
private void decompressTile(final File outputFile, int jp2TileX, int jp2TileY) throws IOException { final int tileIndex = bandInfo.imageLayout.numXTiles * jp2TileY + jp2TileX; final Process process = new ProcessBuilder( EXE, "-i", imageFile.getPath(), "-o", outputFile.getPath(), "-r", getLevel() + "", "-t", tileIndex + "") .directory(cacheDir) .start(); try { final int exitCode = process.waitFor(); if (exitCode != 0) { System.err.println("Failed to uncompress tile: exitCode = " + exitCode); } } catch (InterruptedException e) { System.err.println("InterruptedException: " + e.getMessage()); } }
public void generateDiagram(String outputDirectory, File dotFile) { try { Runtime run = Runtime.getRuntime(); Process pr = run.exec( "dot " + dotFile.getAbsolutePath() + " -Tpng -o" + outputDirectory + FILE_SEPARATOR + "graph.png"); pr.waitFor(); // BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); // should the output be really printed? // String line; // while ( ( line = buf.readLine() ) != null ) // { // System.out.println(line) ; // } // FIXME how to handle exceptions in listener? } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InterruptedException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
public static Either<CommandResult> runCommand( final Context context, final String command, final File path, final List<String> arguments) { try { final List<String> commandAndArgs = new ArrayList<String>(); commandAndArgs.add(command); commandAndArgs.addAll(arguments); final ProcessBuilder pb = new ProcessBuilder(commandAndArgs); if (path != null) { pb.directory(path); } logCommand(context, pb); final Process compilation = pb.start(); final ConsumeStream result = ConsumeStream.start(compilation.getInputStream(), context); final ConsumeStream error = ConsumeStream.start(compilation.getErrorStream(), context); final int exitCode = compilation.waitFor(); result.join(); error.join(); if (result.exception != null) { return Either.fail(result.exception); } if (error.exception != null) { return Either.fail(error.exception); } return Either.success( new CommandResult(result.output.toString(), error.output.toString(), exitCode)); } catch (IOException ex) { return Either.fail(ex); } catch (InterruptedException ex) { return Either.fail(ex); } }
private synchronized void runCmd(String[] cmd) { try { Process p = new ProcessBuilder(cmd).start(); int retval = p.waitFor(); BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream())); String line; List<String> stdout = new ArrayList<>(); while ((line = b.readLine()) != null) { stdout.add(line); } b.close(); b = new BufferedReader(new InputStreamReader(p.getInputStream())); List<String> stderr = new ArrayList<>(); while ((line = b.readLine()) != null) { stderr.add(line); } b.close(); if (retval != 0) { for (String s : stdout) log.info(s); for (String s : stderr) log.info(s); } } catch (Throwable t) { throw new RuntimeException(t); } }
// ## operation runReactor() public void runReactor() { // #[ operation runReactor() // run reactor String dir = System.getProperty("RMG.workingDirectory"); try { // system call for reactor String[] command = {dir + "/software/reactorModel/reactor.exe"}; File runningDir = new File("chemkin"); Process reactor = Runtime.getRuntime().exec(command, null, runningDir); InputStream ips = reactor.getInputStream(); InputStreamReader is = new InputStreamReader(ips); BufferedReader br = new BufferedReader(is); String line = null; while ((line = br.readLine()) != null) { // System.out.println(line); } int exitValue = reactor.waitFor(); } catch (Exception e) { System.out.println("Error in running reactor!"); System.out.println(e.getMessage()); System.exit(0); } // #] }
/** * System command. Execute a command and insert the result. * * @param args * @param help * @param patterns * @param low * @param high */ public String system_internal(boolean allowFail, String args[]) throws Exception { verifyCommand( args, "${" + (allowFail ? "system-allow-fail" : "system") + ";<command>[;<in>]}, execute a system command", null, 2, 3); String command = args[1]; String input = null; if (args.length > 2) { input = args[2]; } Process process = Runtime.getRuntime().exec(command, null, domain.getBase()); if (input != null) { process.getOutputStream().write(input.getBytes("UTF-8")); } process.getOutputStream().close(); String s = IO.collect(process.getInputStream(), "UTF-8"); int exitValue = process.waitFor(); if (exitValue != 0) return exitValue + ""; if (!allowFail && (exitValue != 0)) { domain.error("System command " + command + " failed with " + exitValue); } return s.trim(); }
/* Heck there's no getenv, we have to roll one ourselves! */ public static Hashtable getenv() throws Throwable { Process p; if (File.separator.equals("\\")) { p = Runtime.getRuntime().exec("cmd /c set"); } else { p = Runtime.getRuntime().exec("printenv"); } InputStream in = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; Hashtable table = new Hashtable(); while ((line = reader.readLine()) != null) { int i = line.indexOf('='); if (i > 0) { String name = line.substring(0, i); String value = line.substring(i + 1); table.put(name, value); } } in.close(); p.waitFor(); return table; }
public static String test123() { String r = ""; try { // System.setSecurityManager(null); // String[] callArgs = {"mkdir", "/home/alexis/test123"}; String[] callArgs = {"ls"}; ProcessBuilder pb = new ProcessBuilder(callArgs); pb.redirectErrorStream(true); Process p = pb.start(); p.waitFor(); // BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream() )); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; System.out.println("Start Output"); while ((line = br.readLine()) != null) r += line + "\n"; System.out.println("End Output"); /*Process p = Runtime.getRuntime().exec(callArgs); p.waitFor(); System.out.println("Test Complete");*/ r = line; } catch (IOException e) { System.out.println(e); r = "Test failed"; } catch (Exception e) { } return r; }
/** Run new Maven os process with given arguments and commands. */ public void execute() { Process process = null; BufferedReader br = null; try { ProcessBuilder processBuilder = getProcessBuilder(); processBuilder.redirectErrorStream(true); log.info("Starting process: " + processBuilder.command()); process = processBuilder.start(); // Read output br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = br.readLine()) != null) { System.out.println(line); } process.waitFor(); } catch (Exception e) { throw new RuntimeException(e); } finally { close(br); destroyProcess(process); } }
protected boolean compile(String fileName) { String compiler = "javac"; String classpathOption = "-classpath"; if (jikes != null) { compiler = jikes; classpathOption = "-bootclasspath"; } String[] args = new String[] { compiler, "-d", tmpdir, classpathOption, tmpdir + pathSep + CLASSPATH, tmpdir + "/" + fileName }; String cmdLine = compiler + " -d " + tmpdir + " " + classpathOption + " " + tmpdir + pathSep + CLASSPATH + " " + fileName; // System.out.println("compile: "+cmdLine); File outputDir = new File(tmpdir); try { Process process = Runtime.getRuntime().exec(args, null, outputDir); StreamVacuum stdout = new StreamVacuum(process.getInputStream()); StreamVacuum stderr = new StreamVacuum(process.getErrorStream()); stdout.start(); stderr.start(); process.waitFor(); stdout.join(); stderr.join(); if (stdout.toString().length() > 0) { System.err.println("compile stdout from: " + cmdLine); System.err.println(stdout); } if (stderr.toString().length() > 0) { System.err.println("compile stderr from: " + cmdLine); System.err.println(stderr); } int ret = process.exitValue(); return ret == 0; } catch (Exception e) { System.err.println("can't exec compilation"); e.printStackTrace(System.err); return false; } }
// function to do the compute use case public static void compute() throws Exception { HttpPost method = new HttpPost(url + "/compute"); method.setEntity(new StringEntity(username, "UTF-8")); try { ResponseHandler<String> responseHandler = new BasicResponseHandler(); connIp = client.execute(method, responseHandler); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } System.out.println("Give the file name which has to be put in the grid for computation"); // input of the file name to be computed BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String name = in.readLine(); // get the absolute path of the current working directory File directory = new File("."); String pwd = directory.getAbsolutePath(); // get present time date = new Date(); long start = date.getTime(); String cmd = "java -classpath " + pwd + "/vishwa/JVishwa.jar:. " + name + " " + connIp; System.out.println(cmd); // Execute the vishwa compute process Process p = Runtime.getRuntime().exec(cmd); // wait till the compute process is completed // check for the status code (0 for successful termination) int status = p.waitFor(); if (status == 0) { System.out.println("Compute operation successful. Check the directory for results"); } date = new Date(); long end = date.getTime(); long durationInt = end - start; String duration = String.valueOf(durationInt); method = new HttpPost(url + "/computeAck"); method.setEntity(new StringEntity(username + ";" + duration, "UTF-8")); try { client.execute(method); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } }
String confValue(String name, List<String> extraPaths, boolean daemon) { // The original code from python started a process that started a jvm // with backtype.storm.command.config_value main method that would // read the conf value and print it out to an output stream. python // tapped on to the output stream of that subprocess and returned the // confvalue for the name. Because the pythong code has been shipped // to java now it should not spawn a new process which is a jvm since // we are already in jvm. Instead it should just be doing as the code // commeneted below. // However looking at the pythong code it was // starting a jvm with -cp argument that had classpaths which might // not be available to this java process. Hence there is a chance // that the below code might break existing scripts. As a result I // have decided to still spawn a new process from java just like // python with similar classpaths being constructed for the jvm // execution /*IFn fn = Utils.loadClojureFn("backtype.storm.config", "read-storm-config"); Object o = fn.invoke(); return ((Map) o).get(name).toString();*/ String confValue = ""; ProcessBuilder processBuilder = new ProcessBuilder( this.javaCommand, "-client", this.getConfigOptions(), "-Dstorm.conf.file=" + this.configFile, "-cp", this.getClassPath(extraPaths, daemon), "backtype.storm.command.config_value", name); BufferedReader br; try { Process process = processBuilder.start(); br = new BufferedReader( new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)); process.waitFor(); String line; while ((line = br.readLine()) != null) { String[] tokens = line.split(" "); if ("VALUE:".equals(tokens[0])) { confValue = StringUtils.join(Arrays.copyOfRange(tokens, 1, tokens.length), " "); break; } } br.close(); } catch (Exception ex) { System.out.println( "Exception occured while starting process via " + "processbuilder " + ex.getMessage()); } return confValue; }
public void run() { Throwable tr = null; try { List<Object> cmdArray = ((List<Object>) (new ArrayList<Object>(20))); cmdArray.add(((Object) (SettingsAdapter.getInstance().getMPlayerCommand()))); if (MPlayer.isChangingProcessPrioritySupported()) { cmdArray.add("-priority"); cmdArray.add(((Object) (SettingsAdapter.getInstance().getMPlayerProcessPriority().name()))); } cmdArray.add("-ss"); cmdArray.add(((Object) (Long.toString(mOffset)))); cmdArray.add(((Object) (player.mFile.getPath()))); if (logger.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); String s; for (Iterator<Object> iterator = cmdArray.iterator(); iterator.hasNext(); sb.append(s).append(' ')) s = (String) iterator.next(); logger.debug( ((Object) ((new StringBuilder("Executing [")) .append(((Object) (sb))) .append("]") .toString()))); } mProc = Runtime.getRuntime() .exec((String[]) cmdArray.toArray(((Object[]) (new String[cmdArray.size()])))); logger.debug( ((Object) ((new StringBuilder(" as process ")).append(((Object) (mProc))).toString()))); threadStartupDone = true; StreamGobbler errorGobbler = new StreamGobbler("stderr", mProc.getErrorStream()); errorGobbler.start(); StreamGobbler outputGobbler = new StreamGobbler("stdout", mProc.getInputStream()); outputGobbler.start(); int exitCode = mProc.waitFor(); logger.debug( ((Object) ((new StringBuilder()) .append(((Object) (mProc))) .append(" finished with exit code ") .append(exitCode) .toString()))); } catch (Exception e) { logger.error("", ((Throwable) (e))); tr = ((Throwable) (e)); } finally { threadStartupDone = true; terminated = true; } if (tr != null) player.fireExceptionEvent(tr); }
@Override public Object apply(List<Object> args, Context context) throws ParseException { File outFile = null; String editor = getEditor(); try { outFile = File.createTempFile("stellar_shell", "out"); if (args.size() > 0) { String arg = (String) args.get(0); try (PrintWriter pw = new PrintWriter(outFile)) { IOUtils.write(arg, pw); } } } catch (IOException e) { String message = "Unable to create temp file: " + e.getMessage(); LOG.error(message, e); throw new IllegalStateException(message, e); } Optional<Object> console = context.getCapability(CONSOLE, false); try { PausableInput.INSTANCE.pause(); // shut down the IO for the console ProcessBuilder processBuilder = new ProcessBuilder(editor, outFile.getAbsolutePath()); processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT); try { Process p = processBuilder.start(); // wait for termination. p.waitFor(); try (BufferedReader br = new BufferedReader(new FileReader(outFile))) { String ret = IOUtils.toString(br).trim(); return ret; } } catch (Exception e) { String message = "Unable to read output: " + e.getMessage(); LOG.error(message, e); return null; } } finally { try { PausableInput.INSTANCE.unpause(); if (console.isPresent()) { ((Console) console.get()).pushToInputStream("\b\n"); } } catch (IOException e) { LOG.error("Unable to unpause: " + e.getMessage(), e); } if (outFile.exists()) { outFile.delete(); } } }
private String createTemporaryPreinstallFile() { try { File tempFile = File.createTempFile("preinstall", null); tempFile.deleteOnExit(); InstallUtil.copyResourceToFile("/gnu/io/installer/resources/macosx/preinstall", tempFile); String absPath = tempFile.getAbsolutePath(); Process p = Runtime.getRuntime().exec(new String[] {"chmod", "a+x", absPath}); p.waitFor(); return absPath; } catch (Throwable t) { } return null; }
/** Calls winipcfg and parses the result to find servers and a search path. */ private static void find95() { String s = "winipcfg.out"; try { Process p; p = Runtime.getRuntime().exec("winipcfg /all /batch " + s); p.waitFor(); File f = new File(s); findWin(new FileInputStream(f)); new File(s).delete(); } catch (Exception e) { return; } }
public static int ensureNTServiceIsRunning(String serviceName, String service) throws Exception { ArrayList<String> serviceList = getRunningNTServices(); if (serviceList == null) return -1; // not NT kernel? for (String svc : serviceList) { if (serviceName.equals(svc.trim())) return 0; // service already running } Process process = RUNTIME.exec(comSpec + "net start \"" + service + "\""); process.waitFor(); // wait for the process to complete int rc = process.exitValue(); // pick up its return code boolean success = (rc == 0); if (success) System.out.println("Successfully started service '" + serviceName + "'."); return (success ? 1 : -1); }
void executeStormClass( String className, String jvmType, List<String> jvmOptions, List<String> extraJars, List<String> args, boolean fork, boolean daemon, String daemonName) { List<String> extraPaths = new ArrayList<>(); extraPaths.add(this.clusterConfDirectory); String stormLogDirectory = this.confValue("storm.log.dir", extraPaths, daemon); if ((stormLogDirectory == null) || ("".equals(stormLogDirectory)) || ("nil".equals(stormLogDirectory))) { stormLogDirectory = this.stormHomeDirectory + this.fileSeparator + "logs"; } List<String> commandList = new ArrayList<String>(); commandList.add(this.javaCommand); commandList.add(jvmType); commandList.add("-Ddaemon.name=" + daemonName); commandList.add(this.getConfigOptions()); commandList.add("-Dstorm.home=" + this.stormHomeDirectory); commandList.add("-Dstorm.log.dir=" + stormLogDirectory); commandList.add( "-Djava.library.path=" + this.confValue("java.library.path", extraJars, daemon)); commandList.add("-Dstorm.conf.file=" + this.configFile); commandList.add("-cp"); commandList.add(this.getClassPath(extraJars, daemon)); commandList.addAll(jvmOptions); commandList.add(className); commandList.addAll(args); ProcessBuilder processBuilder = new ProcessBuilder(commandList); processBuilder.inheritIO(); try { Process process = processBuilder.start(); System.out.println("Executing the command: "); String commandLine = StringUtils.join(commandList, " "); System.out.println(commandLine); if (daemon == true) { Runtime.getRuntime().addShutdownHook(new ShutdownHookThread(process, commandLine)); } System.out.println("Waiting for subprocess to finish"); process.waitFor(); System.out.println("subprocess finished"); System.out.println("Exit value from subprocess is :" + process.exitValue()); } catch (Exception ex) { System.out.println( "Exception occured while starting process via " + "processbuilder " + ex.getMessage()); } }
/** Plot the currently selected output buffer */ protected void plotOutput() { try { StringBuffer sb = m_History.getSelectedBuffer(); if (sb != null) { // dump the output into a temporary file File tempDirFile = new File("/tmp"); final File bufferFile = File.createTempFile("buffer", "", tempDirFile); bufferFile.deleteOnExit(); PrintWriter writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(bufferFile))); writer.print(sb); writer.close(); // launch the perl script to process the file // Process proc = Runtime.getRuntime().exec("perl weka/gui/experiment/plot.pl " + // bufferFile.getPath()); Process proc = Runtime.getRuntime() .exec( "perl /u/ml/software/weka-latest/weka/gui/experiment/plot.pl " + bufferFile.getPath()); proc.waitFor(); // get a list of generated gnuplot scripts String[] scriptList = tempDirFile.list( new FilenameFilter() { public boolean accept(File f, String s) { return (s.endsWith(".gplot") && s.startsWith(bufferFile.getName())); } }); for (int i = 0; i < scriptList.length; i++) { // launch gnuplot scriptList[i] = tempDirFile.getPath() + "/" + scriptList[i]; System.out.println(scriptList[i]); proc = Runtime.getRuntime().exec("gnuplot -persist " + scriptList[i]); File plotFile = new File(scriptList[i]); plotFile.deleteOnExit(); File dataFile = new File(scriptList[i].replaceAll(".gplot", ".dat")); dataFile.deleteOnExit(); } } else { m_PlotBut.setEnabled(false); } } catch (Exception e) { System.out.println("Problems plotting: " + e); e.printStackTrace(); } }
/* * Run the given command. */ protected static int run(String message, String[] commandArray) { try { Process process = Runtime.getRuntime().exec(commandArray, null, output); StreamProcessor.start(process.getErrorStream(), StreamProcessor.STDERR, true); StreamProcessor.start(process.getInputStream(), StreamProcessor.STDOUT, true); process.waitFor(); return process.exitValue(); } catch (IOException e) { fail(message, e); } catch (InterruptedException e) { fail(message, e); } return -1; }
static String downloadSiteInfo2(File tmp, String state, String county) { String firstPart = "/Result/search?north=&west=&east=&south=&within=&lat=&long=&statecode="; String secondPart = "&countycode="; String thirdPart = "&siteType=&organization=&siteid=&huc=&sampleMedia=&characteristicType=&characteristicName=&pCode=&startDateLo=&startDateHi=&mimeType=tab&bBox=&zip=yes"; String server = "http://qwwebservices.usgs.gov"; // String state; // String county; // User selects two values in interface // state = "44"; // county = "44%3A001"; String query = firstPart + state + secondPart + county + thirdPart; String finalQuery = server + query; // Execute query and save results to /tmp/mydata.zip try { URL command = new URL(finalQuery); InputStream zipContents = command.openStream(); File temp = new File(tmp, "mydata.zip"); temp.createNewFile(); FileOutputStream out = new FileOutputStream(temp); int x; while ((x = zipContents.read()) != -1) { out.write(x); } out.close(); // Extract the zip file String cmdarray[] = new String[4]; cmdarray[0] = "/usr/bin/unzip"; cmdarray[1] = "-d"; cmdarray[2] = tmp.getAbsolutePath(); cmdarray[3] = temp.getAbsolutePath(); Process unzip = Runtime.getRuntime().exec(cmdarray); unzip.waitFor(); temp.delete(); // There should now be a file at /tmp/data.tsv temp = new File(tmp, "data.tsv"); File data = new File(tmp, "data.txt"); temp.renameTo(data); } catch (Exception e) { e.printStackTrace(); return null; } return finalQuery; }
public static int basic_system_execute_command(Object system_command_line) { String scl = SmartEiffelRuntime.NullTerminatedBytesToString(system_command_line); Process process; try { process = Runtime.getRuntime().exec(scl); process.waitFor(); } catch (Exception e) { System.err.print("SmartEiffelRuntime: basic_system_execute_command(\""); System.err.print(scl); System.err.println("\") failed."); SmartEiffelRuntime.print_run_time_stack(); System.err.println("Try to continue execution."); } return 0; }
/** close all open browsers does not work with Grid */ public void closeAllBrowsers() { // kill all browser procceses String username = System.getenv("USERNAME"); String killExplore = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM IEDriverServer.exe"; // String killFireFox = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM firefox.exe"; String killChrome = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM chromedriver.exe"; // Log.logVerbose("closing all browsers for username: "******"Running: " + killExplore); child = Runtime.getRuntime().exec(killExplore); child.waitFor(); // Log.logVerbose("Running: " + killFireFox); // child = Runtime.getRuntime().exec(killFireFox); // child.waitFor(); // Log.logVerbose("Running: " + killChrome); child = Runtime.getRuntime().exec(killChrome); child.waitFor(); } catch (IOException e) { } catch (InterruptedException e) { } }
/** * Test to see if the thread can access userpath * * @return {@code true} if the local server can access userpath, {@code false} otherwise. */ public boolean testLocalServer() { StringBuilder err = new StringBuilder(); String[] cmds = {ADDE_MCSERVL, "-t"}; String[] env = McIDASV.isWindows() ? getWindowsAddeEnv() : getUnixAddeEnv(); try { Process proc = Runtime.getRuntime().exec(cmds, env); int result = proc.waitFor(); if (result != 0) { return false; } } catch (Exception e) { return false; } return true; }
public static String[] runCommand(String cmd, File dir) throws IOException { Process p = Runtime.getRuntime().exec(cmd.split(" +"), new String[] {}, dir); String[] results = new String[] { IOUtil.readStringFully(p.getInputStream()), IOUtil.readStringFully(p.getErrorStream()) }; try { if (p.waitFor() != 0) throw new RuntimeException( "command failed [" + cmd + "]\n" + results[0] + "\n" + results[1]); } catch (InterruptedException ie) { throw new RuntimeException("uh oh"); } return results; }
static String outputOf(final Process p) { try { Future<String> outputFuture = futureOutputOf(p.getInputStream()); Future<String> errorFuture = futureOutputOf(p.getErrorStream()); final String output = outputFuture.get(); final String error = errorFuture.get(); // Check for successful process completion equal(error, ""); equal(p.waitFor(), 0); equal(p.exitValue(), 0); return output; } catch (Throwable t) { unexpected(t); throw new Error(t); } }