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:com.intbit.PhantomImageConverter.java

public File getImage(String htmlString, JSONArray json_font_list, String width, String height, String x,
        String y) throws Exception {
    File createdHtmlFile = tempHTML(htmlString, json_font_list);
    File createdJSFile = tempJS(createdHtmlFile, width, height, x, y);

    Runtime runTime = Runtime.getRuntime();
    String execPath = "phantomjs " + createdJSFile.getPath();
    //String execPath = "/Users/AR/Downloads/DevSoftware/PhantomJS/phantomjs " + createdJSFile.getPath();

    Process process = runTime.exec(execPath);
    int exitStatus = process.waitFor();
    File tempImagePath = new File(tempPath + File.separator + createdJSFile.getName().replace("js", "png"));
    logger.info(tempImagePath.getPath());

    File fileToSend = tempImagePath;
    if (!StringUtil.isEmpty(this.outputFilePath)) {
        File outputFile = new File(outputFilePath + File.separator + tempImagePath.getName());
        FileUtils.copyFile(tempImagePath, outputFile);
        fileToSend = outputFile;/*from   ww w .  jav a  2  s . co m*/
        tempImagePath.delete();
    }

    createdHtmlFile.delete();
    createdJSFile.delete();

    return fileToSend;
}

From source file:simpleserver.minecraft.MinecraftWrapper.java

public void start() throws InterruptedException {
    minecraftOptions.save();/*from  w ww. j  a v a  2s.c o m*/
    Runtime runtime = Runtime.getRuntime();
    String command = getCommand();

    try {
        minecraft = runtime.exec(command);
    } catch (IOException e) {
        println(e);
        println("FATAL ERROR: Could not start minecraft_server.jar!");
        System.exit(-1);
    }

    active = true;
    wrappers = new LinkedList<Wrapper>();
    wrappers.add(new ShutdownHook(this));
    wrappers.add(new ProcessWrapper(minecraft, messageHandler));

    wrappers.add(new OutputWrapper(minecraft.getInputStream(), messageHandler, "stdout"));
    wrappers.add(new OutputWrapper(minecraft.getErrorStream(), messageHandler, "stderr"));

    inputWrapper = new InputWrapper(systemInput, minecraft.getOutputStream(), messageHandler);
    wrappers.add(inputWrapper);

    messageHandler.waitUntilLoaded();
}

From source file:it.durip_app.OlsrdSettings.java

private void commander(String command) {
    //        Process p = null;
    Process p = null;/*  www.j  a v  a2 s .  c  om*/
    Runtime r = Runtime.getRuntime();
    try {
        p = r.exec(command);
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
}

From source file:it.durip_app.OlsrdSettings.java

private String commanderReturn(String command) {
    Process p = null;/*from www . j av a 2s.  co  m*/
    Runtime r = Runtime.getRuntime();
    try {
        p = r.exec(command);
        BufferedReader ls;
        ls = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String inputLine;
        if ((inputLine = ls.readLine()) != null)
            return inputLine;
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    return "";
}

From source file:com.appcel.core.converter.locator.ConverterLocator.java

@Override
public ConverterExecutor createConverterExecutor(ConverterExecutorEnum executorEnum) {
    ConverterExecutor converterExcutor = null;

    String os = System.getProperty("os.name").toLowerCase();
    // Windows?/*from ww w . ja va 2 s. com*/
    boolean isWindows = (os.indexOf("windows") != -1) ? true : false; // Need a chmod?

    //String archexe = executorEnum.getValue();

    // Temp dir?
    //      File temp = new File(System.getProperty("java.io.tmpdir"), archexe + myEXEversion);
    //      if (!temp.exists()) {
    //         temp.mkdirs();
    //         temp.deleteOnExit();
    //      }

    // converter executable export on disk.
    //      String suffix = isWindows ? ".exe" : "";
    //      File exeFile = new File(temp, archexe + suffix);

    //String executableCmdPath = exeFile.getAbsolutePath();

    //      if (!exeFile.exists()) {
    //
    //         copyFile(archexe + suffix, exeFile);
    //      }
    ConverterConfiguration converterConf = ConverterConfiguration.getMe();

    String openofficeHome = null;
    String swftoolsHome = null;
    String swftoolsExecutor = null;
    String swftoolsFontHome = null;

    if (ConverterExecutorEnum.OPENOFFICE_EXECUTOR.equals(executorEnum)) {

        openofficeHome = isWindows ? converterConf.getConverterOpenofficeWinHome()
                : converterConf.getConverterOpenofficeLinuxHome();

        converterExcutor = new OpenofficeConverterExecutor(openofficeHome,
                ConverterConfiguration.getMe().getConverterOpenofficePort(), !isWindows);

        LOGGER.info("Converter openoffice home Path ??==========>>> " + openofficeHome);

    } else if (ConverterExecutorEnum.SWFTOOLS_EXECUTOR.equals(executorEnum)) {

        swftoolsHome = isWindows ? converterConf.getConverterSwftoolsWinHome()
                : converterConf.getConverterSwftoolsLinuxHome();
        swftoolsFontHome = isWindows ? converterConf.getConverterSwftoolsFontWinHome()
                : converterConf.getConverterSwftoolsFontLinuxHome();
        swftoolsExecutor = isWindows ? converterConf.getConverterSwftoolsWinExecutor()
                : converterConf.getConverterSwftoolsLinuxExecutor();
        converterExcutor = new SwftoolsConverterExecutor(swftoolsHome, swftoolsFontHome, swftoolsExecutor,
                !isWindows);

        LOGGER.info("Converter swftools home Path ??==========>>> " + swftoolsHome);
        LOGGER.info("Converter swfls font home Path ??==========>>> " + swftoolsFontHome);
        LOGGER.info("Converter swftools executor ?==========>>> " + swftoolsExecutor);

    } else {
        throw new ConverterException(
                "Illegal The encoder paramter executor error : " + executorEnum + " is not support.");
    }

    if (!isWindows) {
        Runtime runtime = Runtime.getRuntime();
        try {
            if (StringUtils.isNotBlank(swftoolsFontHome)) {
                runtime.exec(new String[] { "/bin/chmod", "755", swftoolsFontHome });
            }
            if (StringUtils.isNotBlank(swftoolsExecutor)) {
                runtime.exec(new String[] { "/bin/chmod", "755", swftoolsExecutor });
            }

        } catch (IOException e) {
            e.printStackTrace();
            LOGGER.info(" Linux chmod 755 error. ==========>>>" + e.getCause());
        }
    }

    return converterExcutor;
}

From source file:br.unb.bionimbuz.storage.bucket.methods.CloudMethodsAmazonGoogle.java

private void CheckStorageUpBandwith(BioBucket bucket) throws Exception {

    //Upload//  www  .  ja  v  a 2s .c o m
    String command = "/bin/dd if=/dev/zero of=" + bucket.getMountPoint() + "/testfile-" + myId
            + " bs=30M count=1 iflag=nocache oflag=nocache";

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    //System.out.println("\nRunning command: " + command);
    InputStream stderr = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line;

    List<String> output = new ArrayList<>();

    while ((line = br.readLine()) != null) {
        output.add(line);
        //System.out.println("[command] " + line);
    }

    int exitVal = proc.waitFor();
    //System.out.println("[command] Process exitValue: " + exitVal);

    if (exitVal != 0) {
        throw new Exception("Error in command: " + command);
    }

    int pos1, pos2;

    pos1 = output.get(output.size() - 1).indexOf(" copied, ");
    pos1 += 9;

    pos2 = output.get(output.size() - 1).indexOf(" s, ");

    String aux;

    aux = output.get(output.size() - 1).substring(pos1, pos2);
    aux = aux.replace(',', '.');

    float value = Float.parseFloat(aux);

    bucket.setUpBandwith((31 * 1024 * 1024) / value);
}

From source file:br.unb.bionimbuz.storage.bucket.methods.CloudMethodsAmazonGoogle.java

private void CheckStorageDlBandwith(BioBucket bucket) throws Exception {

    //Download /*from  ww  w  . j av a2  s. c om*/
    String command = "/bin/dd if=" + bucket.getMountPoint() + "/testfile-" + myId
            + " of=/tmp/testfile bs=30M count=1 iflag=nocache oflag=nocache";

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    //System.out.println("\nRunning command: " + command);
    InputStream stderr = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line;

    List<String> output = new ArrayList<>();

    while ((line = br.readLine()) != null) {
        output.add(line);
        //System.out.println("[command] " + line);
    }

    int exitVal = proc.waitFor();
    //System.out.println("[command] Process exitValue: " + exitVal);

    if (exitVal != 0) {
        throw new Exception("Error in command: " + command);
    }

    int pos1, pos2;

    pos1 = output.get(output.size() - 1).indexOf(" copied, ");
    pos1 += 9;

    pos2 = output.get(output.size() - 1).indexOf(" s, ");

    String aux;

    aux = output.get(output.size() - 1).substring(pos1, pos2);
    aux = aux.replace(',', '.');

    float value = Float.parseFloat(aux);

    bucket.setDlBandwith((31 * 1024 * 1024) / value);
}

From source file:de.baumann.browser.helper.Activity_password.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_password);
    class_SecurePreferences sharedPrefSec = new class_SecurePreferences(Activity_password.this, "sharedPrefSec",
            "Ywn-YM.XK$b:/:&CsL8;=L,y4", true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }//ww w. ja  v  a2s.  c o  m

    text = (TextView) findViewById(R.id.pass_userPin);

    Button ib0 = (Button) findViewById(R.id.button0);
    assert ib0 != null;
    ib0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("0");
        }
    });

    Button ib1 = (Button) findViewById(R.id.button1);
    assert ib1 != null;
    ib1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("1");
        }
    });

    Button ib2 = (Button) findViewById(R.id.button2);
    assert ib2 != null;
    ib2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("2");
        }
    });

    Button ib3 = (Button) findViewById(R.id.button3);
    assert ib3 != null;
    ib3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("3");
        }
    });

    Button ib4 = (Button) findViewById(R.id.button4);
    assert ib4 != null;
    ib4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("4");
        }
    });

    Button ib5 = (Button) findViewById(R.id.button5);
    assert ib5 != null;
    ib5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("5");
        }
    });

    Button ib6 = (Button) findViewById(R.id.button6);
    assert ib6 != null;
    ib6.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("6");
        }
    });

    Button ib7 = (Button) findViewById(R.id.button7);
    assert ib7 != null;
    ib7.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("7");
        }
    });

    Button ib8 = (Button) findViewById(R.id.button8);
    assert ib8 != null;
    ib8.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("8");
        }
    });

    Button ib9 = (Button) findViewById(R.id.button9);
    assert ib9 != null;
    ib9.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enterNum("9");
        }
    });

    final String protect = sharedPrefSec.getString("protect_PW");

    ImageButton enter = (ImageButton) findViewById(R.id.imageButtonEnter);
    assert enter != null;
    enter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String Password = text.getText().toString().trim();

            if (Password.equals(protect)) {
                helper_main.isOpened(Activity_password.this);
                finish();
            } else {
                Snackbar.make(text, R.string.toast_wrongPW, Snackbar.LENGTH_LONG).show();
            }
        }
    });

    ImageButton cancel = (ImageButton) findViewById(R.id.imageButtonCancel);
    assert cancel != null;
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            text.setText("");
        }
    });

    Button clear = (Button) findViewById(R.id.buttonReset);
    assert clear != null;
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final AlertDialog.Builder dialog = new AlertDialog.Builder(Activity_password.this)
                    .setTitle(R.string.app_conf)
                    .setMessage(helper_main.textSpannable(getString(R.string.pw_forgotten_dialog)))
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            try {
                                // clearing app data
                                Runtime runtime = Runtime.getRuntime();
                                runtime.exec("pm clear de.baumann.browser");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    });
            dialog.show();
        }
    });
}

From source file:org.codequarks.uglifyjsplugin.UglifyJs2Mojo.java

private Process runUglifyJs2Process(File inputFile) throws IOException, InterruptedException {
    Runtime rt = Runtime.getRuntime();
    String command = "uglifyjs " + inputFile.getPath() + " -o " + this.getOutputFile(inputFile).getPath();
    getLog().info("Minifying " + inputFile.getName() + "...");
    getLog().debug("Minifying from " + inputFile.getPath() + " to " + this.getOutputFile(inputFile).getPath());
    return rt.exec(command);
}

From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java

private void start() {

    local_path = FilesystemUtils.getBotAbsolutePath();

    String configPath = askUser(); //Ask user for path; returns "" if nothing selected

    command = EXECUTE_JAR + " " + JAR_FILE + " ";
    if (!configPath.equals("")) {//User indicated a file
        command += CFG_PREFIX + configPath + " ";
    }//  ww w.  ja v a  2 s  .  c om

    command += ARGS;

    Runtime rt = Runtime.getRuntime();
    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            //for windows the launch command requires a different syntax
            command = "cmd /c " + command;
        }

        System.out.println("Launching UI from CLI : $ " + command);
        Process pr = rt.exec(command); //Run

    } catch (IOException e) {
        LOG.error(e.toString());
    }

    System.exit(0);
}