Example usage for java.lang Runtime exec

List of usage examples for java.lang Runtime exec

Introduction

In this page you can find the example usage for java.lang Runtime exec.

Prototype

public Process exec(String cmdarray[]) throws IOException 

Source Link

Document

Executes the specified command and arguments in a separate process.

Usage

From source file:processing.app.CommandLineTest.java

@Test
public void testCommandLineMultipleAction() throws Exception {
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(new String[] { arduinoPath.getAbsolutePath(), "--version", "--verify", });
    pr.waitFor();/*  w w  w .jav a 2s.  c  o  m*/

    Assertions.assertThat(pr.exitValue()).as("Multiple Action will be rejected").isEqualTo(3);
}

From source file:processing.app.CommandLineTest.java

@Test
public void testCommandLineVersion() throws Exception {
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(new String[] { arduinoPath.getAbsolutePath(), "--version", });
    pr.waitFor();/*  w ww .j a va  2 s.  c  o m*/

    Assertions.assertThat(pr.exitValue()).as("Process will finish with exit code 0 in --version").isEqualTo(0);
    Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
            .matches("Arduino: \\d+\\.\\d+\\.\\d+.*");
}

From source file:org.apache.stratos.cartridge.agent.data.publisher.log.FileBasedLogPublisher.java

@Override
public void run() {

    Runtime r = Runtime.getRuntime();
    try {//from   ww w . j a va 2 s.  c  o m
        process = r.exec(Constants.TAIL_COMMAND + filePath);

    } catch (IOException e) {
        log.error("Error tailing file ", e);
        throw new RuntimeException(e);
    }

    log.info("Starting log publisher for file: " + filePath + ", thread: " + Thread.currentThread().getName());

    scanner = new Scanner(process.getInputStream());
    while (scanner.hasNextLine()) {

        DataContext dataContext = new DataContext();
        // set the relevant data
        dataContext.setCorrelationData(null);
        dataContext.setMetaData(new Object[] { memberId });
        dataContext.setPayloadData(
                new Object[] { tenantId, alias, "", datetime, "", scanner.nextLine(), "", "", memberId, "" });
        // publish data
        publish(dataContext);
    }
}

From source file:oscar.util.FaxStatusAction.java

private String getFaxStatus() {
    String output = "$ faxstat -s -l\n";

    if (OscarProperties.getInstance().getBooleanProperty("faxEnable", "yes")) {
        Runtime r = Runtime.getRuntime();
        try {/* ww  w.ja v  a 2 s.  co m*/
            Process p = r.exec("faxstat -s -l");
            InputStream in = p.getInputStream();
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader br = new BufferedReader(isr);
            String line;

            while ((line = br.readLine()) != null) {
                output += line + "\n";
            }

        } catch (IOException e) {
            output += "[An error has been encountered.]\n";
            output += "[" + e.getMessage() + "]\n";
        }
    } else {
        output = "[The fax service is not enabled.]\n";
    }

    return output;

}

From source file:clienteescritorio.Grafica.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {//  w  w w. j  a v  a 2 s. c o  m
        String directorio = System.getProperty("user.dir") + "/temporal/";
        String imagen = "grafica.png";
        String so = System.getProperty("os.name");
        System.err.println("El sso " + so);
        File f = new File(directorio + imagen);
        ChartUtilities.saveChartAsPNG(f, chart, 600, 400);
        Runtime run = Runtime.getRuntime();
        if (so.equals("Linux"))
            run.exec("eog " + directorio + imagen);
        else {
            Desktop dt = Desktop.getDesktop();
            dt.open(f);
        }
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(rootPane, "No se pudo guardar la grfica :(, Intntelo ms tarde!");
        ex.printStackTrace();
    }

}

From source file:com.mycompany.rproject.runnableClass.java

public static void putOutput() throws IOException {
    Runtime r = Runtime.getRuntime();

    StringBuilder sbuilder = new StringBuilder(
            "/usr/local/bin/ffmpeg -i /Users/paulamontojo/Desktop/download.avi -acodec pcm_s16le -ac 1 -ar 16000 /Users/paulamontojo/Desktop/duprueita.wav");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {//from   w ww  .j  a v  a 2  s . c  o m
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
    }

    StringBuilder sbuilder2 = new StringBuilder(
            "mv -f /Users/paulamontojo/Desktop/duprueita.wav /Users/paulamontojo/Downloads/rproject/src/main/resources/edu/cmu/sphinx/demo/aligner/outpone.wav");

    Process p = r.exec(sbuilder.toString());
    Process p2 = r.exec(sbuilder2.toString());
}

From source file:com.ms.commons.standalone.pojo.StandaloneJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap dataMap = context.getMergedJobDataMap();
    String baseStandalonePath = dataMap.getString("baseStandalonePath");
    CronJob cronJob = (CronJob) dataMap.get("cronJob");
    try {//www  . jav a  2  s .c om
        modifyDataSourceProperties(cronJob.getFullClassName(), cronJob.getIdentity(), baseStandalonePath);
    } catch (Exception e1) {
        logger.warn("?job?msun.datasource.properties??"
                + cronJob.getIdentity() + "", e1);
    }

    String cmd = String.format("/bin/bash %s/bin/jobRunner.sh start %s", baseStandalonePath,
            cronJob.getFullClassName());
    Runtime runtime = Runtime.getRuntime();
    Process process = null;
    try {
        process = runtime.exec(cmd);
        process.waitFor();
    } catch (Exception e) {
        logger.error("runtime.exec cmd: " + cmd + " failed");
        throw new JobExecutionException(e);
    } finally {
        if (process != null) {
            process.destroy();
        }
    }
}

From source file:com.liferay.qa.MarkdownBuilder.java

private void html(String file) throws Exception {
    String srcString = "/src/";

    if (_OS_UNIX) {
        srcString = "/src/";
    }//  ww  w .  j  av a  2  s .  co  m

    int x = file.indexOf(srcString) + 1;
    int y = x + 4;

    String fileDir = file.substring(0, x);
    String fileName = file.substring(y);

    new File(fileDir + "html").mkdirs();

    x = fileName.indexOf(".markdown");

    String testName = fileName.substring(0, x);

    String[] command;

    if (_OS_UNIX) {
        String[] unixCommand = { _PANDOC_APP, "-f", "markdown", "-t", "html", "-o",
                fileDir + "html/" + testName + ".html", fileDir + "src/" + testName + ".markdown" };

        command = unixCommand;
    } else {
        String[] windowsCommand = { _PANDOC_APP, "-f", "markdown", "-t", "html", "+RTS", "-K64m", "-RTS",
                "-smart", "-o", fileDir + "html/" + testName + ".html",
                fileDir + "src/" + testName + ".markdown" };

        command = windowsCommand;
    }

    Runtime runtime = Runtime.getRuntime();

    runtime.exec(command);
}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4.wsgram.ConfigureWSGram.java

public void remoteShellAccessForPBS() throws WSGramException {
    String cmd = globusLoc + "setup/globus/setup-globus-job-manager-pbs --remote-shell=rsh";
    cmd = cmd.replace('/', File.separatorChar);
    cmd = cmd.replace('\\', File.separatorChar);

    Process p = null;/*from   ww w.j ava 2s.c o  m*/
    Runtime rt = Runtime.getRuntime();
    int exitVal = 0;
    try {
        p = rt.exec(cmd);
        exitVal = p.waitFor();
    } catch (IOException ie) {
        log.error("Error while configuring remote shell for rsh access for PBS", ie);
        throw new WSGramException("Error while configuring remote shell for rsh access for PBS", ie);
    } catch (InterruptedException ine) {
        log.error("Error while configuring remote shell for rsh access for PBS", ine);
        throw new WSGramException("Error while configuring remote shell for rsh access for PBS", ine);
    }

    if (exitVal != 0) {
        log.error("Error while configuring remote shell for rsh access for PBS..."
                + "returned with exit value : " + exitVal);
        throw new WSGramException("Error while configuring remote shell for rsh access for PBS..."
                + "returned with exit value : " + exitVal);
    }

    log.info("Configured remote shell for rsh access for PBS.");
}

From source file:com.samir.commons.java.jarinstallerkit.jarinstaller.JarInstaller.java

public String runCommandAsync(String path, String param) throws IOException {
    Runtime runtime = Runtime.getRuntime();
    final String pathExec = getCommand(path, param);
    runtime.exec(pathExec);
    return pathExec;
}