Search in sources :

Example 41 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class ProcessListUtil method parseCommandOutput.

@Nullable
private static List<ProcessInfo> parseCommandOutput(@NotNull List<String> command, @NotNull NullableFunction<String, List<ProcessInfo>> parser) {
    String output;
    try {
        ProcessOutput processOutput = ExecUtil.execAndGetOutput(new GeneralCommandLine(command));
        int exitCode = processOutput.getExitCode();
        if (exitCode != 0) {
            LOG.error("Cannot get process list, command '" + StringUtil.join(command, " ") + "' exited with code " + exitCode + ", stdout:\n" + processOutput.getStdout() + "\nstderr:\n" + processOutput.getStderr());
        }
        output = processOutput.getStdout();
    } catch (ExecutionException e) {
        LOG.error("Cannot get process list", e);
        return null;
    }
    return parser.fun(output);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class CreateLauncherScriptAction method createLauncherScript.

public static void createLauncherScript(@NotNull String pathName) throws Exception {
    if (!isAvailable())
        return;
    File scriptFile = createLauncherScriptFile();
    try {
        File scriptTarget = new File(pathName);
        File scriptTargetDir = scriptTarget.getParentFile();
        assert scriptTargetDir != null : "path: " + pathName;
        if (!(scriptTargetDir.exists() || scriptTargetDir.mkdirs()) || !scriptFile.renameTo(scriptTarget)) {
            String scriptTargetDirPath = scriptTargetDir.getCanonicalPath();
            // copy file and change ownership to root (UID 0 = root, GID 0 = root (wheel on Macs))
            String installationScriptSrc = "#!/bin/sh\n" + "mkdir -p \"" + scriptTargetDirPath + "\"\n" + "install -g 0 -o 0 \"" + scriptFile.getCanonicalPath() + "\" \"" + pathName + "\"";
            File installationScript = ExecUtil.createTempExecutableScript("launcher_installer", ".sh", installationScriptSrc);
            String prompt = ApplicationBundle.message("launcher.script.sudo.prompt", scriptTargetDirPath);
            ProcessOutput result = ExecUtil.sudoAndGetOutput(new GeneralCommandLine(installationScript.getPath()), prompt);
            int exitCode = result.getExitCode();
            if (exitCode != 0) {
                String message = "Launcher script creation failed with " + exitCode;
                String output = result.getStdout();
                if (!StringUtil.isEmptyOrSpaces(output))
                    message += "\nOutput: " + output.trim();
                throw new RuntimeException(message);
            }
        }
    } finally {
        if (scriptFile.exists()) {
            FileUtil.delete(scriptFile);
        }
    }
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) File(java.io.File)

Example 43 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class GeneralCommandLineTest method execAndGetOutput.

private static String execAndGetOutput(GeneralCommandLine commandLine) throws ExecutionException {
    ProcessOutput output = ExecUtil.execAndGetOutput(commandLine);
    int ec = output.getExitCode();
    if (ec != 0) {
        fail("Command:\n" + commandLine.getCommandLineString() + "\nStdOut:\n" + output.getStdout() + "\nStdErr:\n" + output.getStderr());
    }
    return output.getStdout();
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 44 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class SvnExecutableChecker method validateLocale.

@Nullable
private Notification validateLocale() throws SvnBindException {
    ProcessOutput versionOutput = getVersionClient().runCommand(false);
    Notification result = null;
    Matcher matcher = INVALID_LOCALE_WARNING_PATTERN.matcher(versionOutput.getStderr());
    if (matcher.find()) {
        LOG.info(matcher.group());
        result = new ExecutableNotValidNotification(prepareDescription(UIUtil.getHtmlBody(matcher.group()), false), NotificationType.WARNING);
    } else if (!isEnglishOutput(versionOutput.getStdout())) {
        LOG.info("\"svn --version\" command contains non-English output " + versionOutput.getStdout());
        result = new ExecutableNotValidNotification(prepareDescription(SvnBundle.message("non.english.locale.detected.warning"), false), NotificationType.WARNING);
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) ProcessOutput(com.intellij.execution.process.ProcessOutput) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class HgTestRepository method create.

/**
   * Creates a new Mercurial repository in a new temporary test directory.
   * @param test reference to the test case instance.
   * @return created repository.
   */
public static HgTestRepository create(HgTest test) throws Exception {
    final TempDirTestFixture dirFixture = createFixtureDir();
    final File repo = new File(dirFixture.getTempDirPath());
    final ProcessOutput processOutput = test.runHg(repo, "init");
    AbstractVcsTestCase.verify(processOutput);
    return new HgTestRepository(test, dirFixture);
}
Also used : TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ProcessOutput(com.intellij.execution.process.ProcessOutput) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ProcessOutput (com.intellij.execution.process.ProcessOutput)57 File (java.io.File)22 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 ExecutionException (com.intellij.execution.ExecutionException)18 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PsiFile (com.intellij.psi.PsiFile)3 SkeletonVersionChecker.fromVersionString (com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString)3 IOException (java.io.IOException)3 PhoneGapCommandLine (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine)2 Change (com.intellij.openapi.vcs.changes.Change)2 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)2 TempDirTestFixture (com.intellij.testFramework.fixtures.TempDirTestFixture)2