Java File Attribute launchExecutable(String executable, List args, Preferences preferences)

Here you can find the source of launchExecutable(String executable, List args, Preferences preferences)

Description

launch Executable

License

Open Source License

Declaration

public static Process launchExecutable(String executable,
            List<String> args, Preferences preferences) 

Method Source Code

//package com.java2s;
/*//w  w w.  ja v  a2 s  . co  m
 * Copyright (C) 2017 Jean-R?my Buchs <jrb0001@692b8c32.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import java.util.List;
import java.util.prefs.Preferences;

public class Main {
    public static Process launchExecutable(String executable,
            List<String> args, Preferences preferences) {
        List<String> command = new ArrayList<>();

        try {
            if (preferences.get("commandMono", "mono").isEmpty()) {
                command.add(new File(preferences.get("basedir", null),
                        "working").getAbsolutePath() + "/" + executable);
            } else {
                command.add(preferences.get("commandMono", "mono"));
                command.add(executable);
            }
            command.addAll(args);

            return new ProcessBuilder(command)
                    .directory(
                            new File(preferences.get("basedir", null),
                                    "working")).inheritIO().start();
        } catch (IOException ex) {
            throw new RuntimeException("Failed to launch " + executable, ex);
        }
    }
}

Related

  1. findInPath(String executable, String path, String pathSeparator)
  2. findJavaCompilerExecutableInDir(File dir)
  3. findJavaExecutable(File vmInstallLocation)
  4. findUnixExecutable(String unixCommandLineExecutables)
  5. javaExecutable(File jre)
  6. makeCurrentDirectoryThatOfExecutable(String executable)
  7. makeExecutable(File file)
  8. makeExecutable(File file)
  9. makeExecutable(File file)