List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:com.mycompany.neo4jprotein.neoStart.java
private static void registerShutdownHook(final GraphDatabaseService graphDb) { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you "Ctrl-C" the // running application). Runtime.getRuntime().addShutdownHook(new Thread() { @Override/*from w w w .j a v a2s .com*/ public void run() { graphDb.shutdown(); } }); }
From source file:Main.java
public Main() throws Exception { ps = Runtime.getRuntime().exec("java Test"); }
From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java
public static void main(String[] args) { loadUserProperties();//from www . ja v a 2 s. c om configureLog4j(); ApplicationArgs appArgs = new ApplicationArgs(); parseArgs(args, appArgs); String projectPath = parseProjectPathArg(appArgs); final String contentPath = defaultIfEmpty(appArgs.getContentRoot(), projectPath + CONTENT_DIR); final String testsPath = defaultIfEmpty(appArgs.getTestRoot(), projectPath + TEST_DIR); List<String> testSuites = parseTestSuites(appArgs); boolean shouldPrintCoverageData = appArgs.shouldOutputCoverage(); boolean runTestsInParallel = appArgs.isParallel(); int threadCount = parseThreadCountArg(appArgs, runTestsInParallel); String testCaseTimeout = parseTestTimeout(appArgs); setProperty(TEST_CASE_TIMEOUT_IN_MINUTES_KEY, valueOf(testCaseTimeout)); final boolean shouldValidateDescription = appArgs.shouldValidateDescription(); final boolean shouldValidateCheckstyle = appArgs.shouldValidateCheckstyle(); String runConfigPath = FilenameUtils.normalize(appArgs.getRunConfigPath()); BuildMode buildMode = null; Set<String> changedFiles = null; try { String smartModePath = appArgs.getChangesOnlyConfigPath(); if (StringUtils.isEmpty(smartModePath)) { buildMode = BuildMode.BASIC; changedFiles = new HashSet<>(); printBuildModeInfo(buildMode); } else { buildMode = BuildMode.CHANGED; changedFiles = readChangedFilesFromSource(smartModePath); printBuildModeInfo(buildMode); } } catch (Exception ex) { log.error("Exception: " + ex.getMessage()); System.exit(1); } // Override with the values from the file if configured List<String> testSuitesParallel = new ArrayList<>(); List<String> testSuitesSequential = new ArrayList<>(); BulkRunMode bulkRunMode = runTestsInParallel ? ALL_PARALLEL : ALL_SEQUENTIAL; TestCaseRunMode unspecifiedTestSuiteRunMode = runTestsInParallel ? TestCaseRunMode.PARALLEL : TestCaseRunMode.SEQUENTIAL; if (get(runConfigPath).isAbsolute() && isRegularFile(get(runConfigPath), NOFOLLOW_LINKS) && equalsIgnoreCase(PROPERTIES_FILE_EXTENSION, FilenameUtils.getExtension(runConfigPath))) { Properties runConfigurationProperties = ArgumentProcessorUtils.getPropertiesFromFile(runConfigPath); shouldPrintCoverageData = getBooleanFromPropertiesWithDefault(TEST_COVERAGE, shouldPrintCoverageData, runConfigurationProperties); threadCount = getIntFromPropertiesWithDefaultAndRange(TEST_PARALLEL_THREAD_COUNT, Runtime.getRuntime().availableProcessors(), runConfigurationProperties, 1, MAX_THREADS_TEST_RUNNER + 1); testSuites = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_TO_RUN); testSuitesParallel = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_PARALLEL); testSuitesSequential = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_SEQUENTIAL); addErrorIfSameTestSuiteIsInBothParallelOrSequential(testSuitesParallel, testSuitesSequential); unspecifiedTestSuiteRunMode = getEnumInstanceFromPropertiesWithDefault(TEST_SUITES_RUN_UNSPECIFIED, unspecifiedTestSuiteRunMode, runConfigurationProperties); addWarningsForMisconfiguredTestSuites(unspecifiedTestSuiteRunMode, testSuites, testSuitesSequential, testSuitesParallel); bulkRunMode = POSSIBLY_MIXED; } else { // Warn when file is misconfigured, relative path, file does not exist or is not a properties file log.info(format(DID_NOT_DETECT_RUN_CONFIGURATION_PROPERTIES_FILE, runConfigPath)); } String testCaseReportLocation = getProperty(TEST_CASE_REPORT_LOCATION); if (StringUtils.isBlank(testCaseReportLocation)) { log.info("Test case report location property [" + TEST_CASE_REPORT_LOCATION + "] is not defined. Report will be skipped."); } // Setting thread count for visibility in ParallelTestCaseExecutorService setProperty(SLANG_TEST_RUNNER_THREAD_COUNT, valueOf(threadCount)); log.info(NEW_LINE + "------------------------------------------------------------"); log.info("Building project: " + projectPath); log.info("Content root is at: " + contentPath); log.info("Test root is at: " + testsPath); log.info("Active test suites are: " + getListForPrint(testSuites)); log.info("Parallel run mode is configured for test suites: " + getListForPrint(testSuitesParallel)); log.info("Sequential run mode is configured for test suites: " + getListForPrint(testSuitesSequential)); log.info("Default run mode '" + unspecifiedTestSuiteRunMode.name().toLowerCase() + "' is configured for test suites: " + getListForPrint( getDefaultRunModeTestSuites(testSuites, testSuitesParallel, testSuitesSequential))); log.info("Bulk run mode for tests: " + getBulkModeForPrint(bulkRunMode)); log.info("Print coverage data: " + valueOf(shouldPrintCoverageData)); log.info("Validate description: " + valueOf(shouldValidateDescription)); log.info("Validate checkstyle: " + valueOf(shouldValidateCheckstyle)); log.info("Thread count: " + threadCount); log.info("Test case timeout in minutes: " + (isEmpty(testCaseTimeout) ? valueOf(MAX_TIME_PER_TESTCASE_IN_MINUTES) : testCaseTimeout)); log.info(NEW_LINE + "Loading..."); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/testRunnerContext.xml"); context.registerShutdownHook(); SlangBuilder slangBuilder = context.getBean(SlangBuilder.class); LoggingService loggingService = context.getBean(LoggingServiceImpl.class); Slang slang = context.getBean(Slang.class); try { updateTestSuiteMappings(context.getBean(TestRunInfoService.class), testSuitesParallel, testSuitesSequential, testSuites, unspecifiedTestSuiteRunMode); registerEventHandlers(slang); List<RuntimeException> exceptions = new ArrayList<>(); SlangBuildResults buildResults = slangBuilder.buildSlangContent(projectPath, contentPath, testsPath, testSuites, shouldValidateDescription, shouldValidateCheckstyle, bulkRunMode, buildMode, changedFiles); exceptions.addAll(buildResults.getCompilationExceptions()); if (exceptions.size() > 0) { logErrors(exceptions, projectPath, loggingService); } IRunTestResults runTestsResults = buildResults.getRunTestsResults(); Map<String, TestRun> skippedTests = runTestsResults.getSkippedTests(); if (isNotEmpty(skippedTests)) { printSkippedTestsSummary(skippedTests, loggingService); } printPassedTests(runTestsResults, loggingService); if (shouldPrintCoverageData) { printTestCoverageData(runTestsResults, loggingService); } if (isNotEmpty(runTestsResults.getFailedTests())) { printBuildFailureSummary(projectPath, runTestsResults, loggingService); } else { printBuildSuccessSummary(contentPath, buildResults, runTestsResults, loggingService); } loggingService.waitForAllLogTasksToFinish(); generateTestCaseReport(context.getBean(SlangTestCaseRunReportGeneratorService.class), runTestsResults, testCaseReportLocation); System.exit(isNotEmpty(runTestsResults.getFailedTests()) ? 1 : 0); } catch (Throwable e) { logErrorsPrefix(loggingService); loggingService.logEvent(Level.ERROR, "Exception: " + e.getMessage()); logErrorsSuffix(projectPath, loggingService); loggingService.waitForAllLogTasksToFinish(); System.exit(1); } }
From source file:Main.java
public static int shellExecute(String strCommand, boolean bDisplayProgramOutput) { Process p = null;//from w ww .j a v a 2 s . c o m try { p = Runtime.getRuntime().exec(strCommand); } catch (IOException e) { e.printStackTrace(); } if (p != null) { BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; try { line = input.readLine(); if (bDisplayProgramOutput && line != null) System.out.println(line); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while (line != null) { try { line = input.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (bDisplayProgramOutput && line != null) System.out.println(line); } try { p.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return p.exitValue(); } return -1; }
From source file:Main.java
public static String getSuVersion() { Process process = null;//from w w w. j av a 2s.c om String inLine = null; try { process = Runtime.getRuntime().exec("sh"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); BufferedReader is = new BufferedReader( new InputStreamReader(new DataInputStream(process.getInputStream())), 64); os.writeBytes("su -v\n"); // We have to hold up the thread to make sure that we're ready to read // the stream, using increments of 5ms makes it return as quick as // possible, and limiting to 1000ms makes sure that it doesn't hang for // too long if there's a problem. for (int i = 0; i < 400; i++) { if (is.ready()) { break; } try { Thread.sleep(5); } catch (InterruptedException e) { Log.w(TAG, "Sleep timer got interrupted..."); } } if (is.ready()) { inLine = is.readLine(); if (inLine != null) { return inLine; } } else { os.writeBytes("exit\n"); } } catch (IOException e) { Log.e(TAG, "Problems reading current version.", e); return null; } finally { if (process != null) { process.destroy(); } } return null; }
From source file:MiscUtils.java
public static void openBrowser(String url) throws IOException { final String os = System.getProperty("os.name").toLowerCase(); if (os.indexOf("windows") != -1) { url = appendUrlForWindows2000(os, url); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); return;/*from ww w . j a va 2s . c om*/ } else if (os.indexOf("mac") != -1) { Runtime.getRuntime().exec(new String[] { "open", url }); return; } else { Runtime runtime = Runtime.getRuntime(); for (int i = 0; i < browserNames.length; i++) { try { runtime.exec(new String[] { browserNames[i], url }); return; } catch (Exception e) { } } } }
From source file:BareBonesBrowserLaunch.java
public static void openURL(String url) { String osName = System.getProperty("os.name"); try {/*from w w w. ja va 2 s . co m*/ if (osName.startsWith("Mac OS")) { Class fileMgr = Class.forName("com.apple.eio.FileManager"); Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class }); openURL.invoke(null, new Object[] { url }); } else if (osName.startsWith("Windows")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); else { //assume Unix or Linux String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0) browser = browsers[count]; if (browser == null) throw new Exception("Could not find web browser"); else Runtime.getRuntime().exec(new String[] { browser, url }); } } catch (Exception e) { JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); } }
From source file:com.ltb.Main.java
public static void displayIt(File node) throws IOException, InterruptedException { String filePath = node.getAbsoluteFile().getAbsolutePath(); System.out.println(filePath); if (node.isDirectory()) { String[] subNote = node.list(); for (String filename : subNote) { displayIt(new File(node, filename)); }/* w w w .ja va 2 s . c om*/ } else { //Process pr = Runtime.getRuntime().exec("avconv -i //home//juanma//Videos//License.avi"); // Working fine //Process pr = Runtime.getRuntime().exec(outLine); // Working fine without spaces String[] args1 = { "avconv", "-i", filePath }; Process pr = Runtime.getRuntime().exec(args1); //filePath = filePath.replace("/" , "//"); //filePath = filePath.replace(" " , "\\ "); //String commandline ="avconv -i \""+filePath+"\""; //String commandline ="avconv -i "+filePath; //Process pr = Runtime.getRuntime().exec(commandline); BufferedReader in = new BufferedReader(new InputStreamReader(pr.getErrorStream())); //BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line; // Start FilmFactory String extension = FilenameUtils.getExtension(node.getName()); if (isFilmExtension(extension) == false) { return; } else { Film film = new Film(node.getName(), filePath); while ((line = in.readLine()) != null) { System.out.println(line); if (line.contains("Invalid data")) { // TODO Most probably no film - Change method below film.isNotFilm(); } else if (line.contains("Audio")) { film.addAudioTrack(line); } else if (line.contains("No such file")) { System.out.println("Error?"); } } pr.waitFor(); in.close(); } } }
From source file:com.github.stagirs.lingvo.syntax.disambiguity.mystem.MyStem.java
public static List<SyntaxItem[][]> process(List<String> text) throws IOException, InterruptedException { FileUtils.writeLines(new File("mystem_input"), "utf-8", text); Process process = Runtime.getRuntime() .exec(new String[] { "./mystem", "-c", "-i", "-d", "mystem_input", "mystem_output" }); process.waitFor();// w w w .ja v a 2 s.com InputStream is = process.getInputStream(); try { List<String> lines = FileUtils.readLines(new File("mystem_output"), "utf-8"); List<SyntaxItem[][]> resultList = new ArrayList<SyntaxItem[][]>(); for (String line : lines) { String[] parts = line.split(" "); SyntaxItem[][] result = new SyntaxItem[parts.length][]; for (int i = 0; i < result.length; i++) { if (parts[i].isEmpty()) { result[i] = new SyntaxItem[0]; continue; } if (!parts[i].contains("{")) { final String word = parts[i]; result[i] = new SyntaxItem[] { new SyntaxItem() { @Override public String getName() { return word; } @Override public String getType() { return ""; } @Override public double getScore() { return 0; } } }; continue; } final String word = parts[i].substring(0, parts[i].indexOf('{')); final String[] forms = parts[i].substring(parts[i].indexOf('{') + 1, parts[i].indexOf('}')) .split("\\|"); result[i] = new SyntaxItem[forms.length]; for (int j = 0; j < result[i].length; j++) { final String type = forms[j]; result[i][j] = new SyntaxItem() { @Override public String getName() { return word; } @Override public String getType() { return type; } @Override public double getScore() { return 0; } }; } } resultList.add(result); } return resultList; } finally { is.close(); } }