List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:ExecDemoSort.java
public static void main(String[] av) throws IOException { // A Runtime object has methods for dealing with the OS Runtime r = Runtime.getRuntime(); // A process object tracks one external running process Process p;/*from w ww . java 2 s.c o m*/ // file contains unsorted data p = r.exec("sort sortdemo.txt"); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); System.out.println("Here is your sorted data:"); String aLine; while ((aLine = is.readLine()) != null) System.out.println(aLine); System.out.println("That is all, folks!"); return; }
From source file:ezbake.local.accumulo.LocalAccumulo.java
public static void main(String args[]) throws Exception { Logger logger = LoggerFactory.getLogger(LocalAccumulo.class); final File accumuloDirectory = Files.createTempDir(); int shutdownPort = 4445; MiniAccumuloConfig config = new MiniAccumuloConfig(accumuloDirectory, "strongpassword"); config.setZooKeeperPort(12181);/* w w w . ja va 2 s . c om*/ final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(config); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { accumulo.stop(); FileUtils.deleteDirectory(accumuloDirectory); System.out.println("\nShut down gracefully on " + new Date()); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); accumulo.start(); printInfo(accumulo, shutdownPort); if (args.length > 0) { logger.info("Adding the following authorizations: {}", Arrays.toString(args)); Authorizations auths = new Authorizations(args); Instance inst = new ZooKeeperInstance(accumulo.getConfig().getInstanceName(), accumulo.getZooKeepers()); Connector client = inst.getConnector("root", new PasswordToken(accumulo.getConfig().getRootPassword())); logger.info("Connected..."); client.securityOperations().changeUserAuthorizations("root", auths); logger.info("Auths updated"); } // start a socket on the shutdown port and block- anything connected to this port will activate the shutdown ServerSocket shutdownServer = new ServerSocket(shutdownPort); shutdownServer.accept(); System.exit(0); }
From source file:es.upv.grycap.opengateway.examples.AppDaemon.java
/** * Main entry point to the application./*from w w w . jav a 2 s . c om*/ * @param args - arguments passed to the application * @throws Exception - if the application fails to start the required services */ public static void main(final String[] args) throws Exception { final AppDaemon daemon = new AppDaemon(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { daemon.stop(); } catch (Exception e) { System.err.println( new StringBuffer("Failed to stop application: ").append(e.getMessage()).toString()); } try { daemon.destroy(); } catch (Exception e) { System.err.println( new StringBuffer("Failed to stop application: ").append(e.getMessage()).toString()); } } }); daemon.init(new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return args; } }); daemon.start(); }
From source file:edu.hawaii.soest.pacioos.text.TextSourceApp.java
/** * @param args/*from w w w.j a v a 2s.co m*/ */ public static void main(String[] args) { String xmlConfiguration = null; if (args.length != 1) { log.error("Please provide the path to the instrument's XML configuration file " + "as a single parameter."); System.exit(1); } else { xmlConfiguration = args[0]; } try { textSource = TextSourceFactory.getSimpleTextSource(xmlConfiguration); if (textSource != null) { textSource.start(); } // Handle ctrl-c's and other abrupt death signals to the process Runtime.getRuntime().addShutdownHook(new Thread() { // stop the streaming process public void run() { log.info("Stopping the SimpleTextSource driver due to user request"); textSource.stop(); } }); } catch (ConfigurationException e) { if (log.isDebugEnabled()) { e.printStackTrace(); } log.error("There was a problem configuring the driver. The error message was: " + e.getMessage()); System.exit(1); } }
From source file:org.robotbrains.data.cloud.timeseries.server.ServerMain.java
public static void main(String[] args) throws Exception { final ServerMain main = new ServerMain(args); main.startup();//from w w w .j a v a 2 s . c o m Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Shutdown hook ran!"); main.shutdown(); } }); }
From source file:com.google.endpoints.examples.bookstore.BookstoreServer.java
public static void main(String[] args) throws Exception { Options options = createOptions();/*www .j a v a 2 s . c o m*/ CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } int port = DEFAULT_PORT; if (line.hasOption("port")) { String portOption = line.getOptionValue("port"); try { port = Integer.parseInt(portOption); } catch (java.lang.NumberFormatException e) { System.err.println("Invalid port number: " + portOption); printUsage(options); return; } } final BookstoreData data = initializeBookstoreData(); final BookstoreServer server = new BookstoreServer(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { System.out.println("Shutting down"); server.stop(); } catch (Exception e) { e.printStackTrace(); } } }); server.start(port, data); System.out.format("Bookstore service listening on %d\n", port); server.blockUntilShutdown(); }
From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.Main.java
/** * Entry point of Cognition-DNC/*from w ww .jav a 2s . c o m*/ */ public static void main(String[] args) { printGNULicense(); if (requiresHelp(args)) { CommandHelper.printHelp(); System.exit(0); } String path = "file:" + getCurrentFolder() + File.separator + "config" + File.separator + "applicationContext.xml"; logger.info("Loading context from " + path); context = new ClassPathXmlApplicationContext(path); Options options = getOptions(); CommandLineParser parser = new GnuParser(); Runtime.getRuntime().addShutdownHook(getShutDownBehaviour()); try { CommandLine cmd = parser.parse(options, args); processCommands(cmd); } catch (Exception e) { e.printStackTrace(); } }
From source file:morphy.Morphy.java
public static void main(String[] args) { if (args.length == 0) { System.out.println("Please specify path to configuration file (morphy.properties)."); System.exit(1);/* w w w .j a v a2 s . c om*/ } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { getInstance().shutdown(); } }); String filePath = args[0]; File configFile = ensureConfigFileExistsAndReadable(filePath); getInstance().init(configFile); }
From source file:Interface.Teste.java
public static void main(String[] args) { try {//from ww w. j a v a 2s. c o m //Runtime.getRuntime().exec("cmd /c start Ajuda.pdf"); Runtime.getRuntime().exec( "cmd /c start C://Users//Junior//Documents//NetBeansProjects//SnackBar1//src//Interface//Ajuda.pdf"); } catch (IOException ex) { Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex); } Teste t = new Teste(); t.setSize(600, 600); t.setVisible(true); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:com.msopentech.ThaliClient.ProxyDesktop.java
public static void main(String[] rgs) throws InterruptedException, URISyntaxException, IOException { final ProxyDesktop instance = new ProxyDesktop(); try {/*from w ww.ja va2 s. co m*/ instance.initialize(); } catch (RuntimeException e) { System.out.println(e); } // Attempt to launch the default browser to our page if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI("http://localhost:" + localWebserverPort)); } // Register to shutdown the server properly from a sigterm Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { instance.shutdown(); } }); // Let user press enter to kill the console session Console console = System.console(); if (console != null) { console.format("\nPress ENTER to exit.\n"); console.readLine(); instance.shutdown(); } else { // Don't exit on your own when running without a console (debugging in an IDE). while (true) { Thread.sleep(500); } } }