Search in sources :

Example 6 with ProcessHandler

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

the class ConfigurationBasedProcessRunner method runProcess.

@Override
final void runProcess(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final ProcessListener processListener, @NotNull final String tempWorkingPath) throws ExecutionException {
    ensureConsoleOk(myConsole);
    // Do not create new environment from factory, if child provided environment to rerun
    final ExecutionEnvironment executionEnvironment = // TODO: RENAME
    (myRerunExecutionEnvironment != null ? myRerunExecutionEnvironment : createExecutionEnvironment(sdkPath, project, tempWorkingPath));
    // Engine to be run after process end to post process console
    final ProcessListener consolePostprocessor = new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            super.processTerminated(event);
            ApplicationManager.getApplication().invokeAndWait(() -> prepareConsoleAfterProcessEnd(), ModalityState.NON_MODAL);
        }
    };
    /// Find all available runners to report them to the test
    myAvailableRunnersForLastRun.clear();
    for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
        for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
            if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
                myAvailableRunnersForLastRun.add(runner);
            }
        }
    }
    executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {

        @Override
        public void processStarted(final RunContentDescriptor descriptor) {
            final ProcessHandler handler = descriptor.getProcessHandler();
            assert handler != null : "No process handler";
            handler.addProcessListener(consolePostprocessor);
            handler.addProcessListener(processListener);
            myConsole = null;
            fetchConsoleAndSetToField(descriptor);
            assert myConsole != null : "fetchConsoleAndSetToField did not set console!";
            // Console does not work with out of this method
            final JComponent component = myConsole.getComponent();
            assert component != null;
            myLastProcessDescriptor = descriptor;
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 7 with ProcessHandler

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

the class PyDebuggerTask method disposeDebugProcess.

@Override
protected void disposeDebugProcess() throws InterruptedException {
    if (myDebugProcess != null) {
        ProcessHandler processHandler = myDebugProcess.getProcessHandler();
        myDebugProcess.stop();
        waitFor(processHandler);
        if (!processHandler.isProcessTerminated()) {
            killDebugProcess();
            if (!waitFor(processHandler)) {
                new Throwable("Cannot stop debugger process").printStackTrace();
            }
        }
    }
}
Also used : KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 8 with ProcessHandler

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

the class PythonCommandLineState method startProcess.

/**
   * Patches the command line parameters applying patchers from first to last, and then runs it.
   *
   * @param processStarter
   * @param patchers any number of patchers; any patcher may be null, and the whole argument may be null.
   * @return handler of the started process
   * @throws ExecutionException
   */
@NotNull
protected ProcessHandler startProcess(PythonProcessStarter processStarter, CommandLinePatcher... patchers) throws ExecutionException {
    GeneralCommandLine commandLine = generateCommandLine(patchers);
    // Extend command line
    PythonRunConfigurationExtensionsManager.getInstance().patchCommandLine(myConfig, getRunnerSettings(), commandLine, getEnvironment().getRunner().getRunnerId());
    ProcessHandler processHandler = processStarter.start(myConfig, commandLine);
    // attach extensions
    PythonRunConfigurationExtensionsManager.getInstance().attachExtensionsToProcess(myConfig, processHandler, getRunnerSettings());
    return processHandler;
}
Also used : ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ProcessHandler

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

the class PythonCommandLineState method execute.

public ExecutionResult execute(Executor executor, PythonProcessStarter processStarter, CommandLinePatcher... patchers) throws ExecutionException {
    final ProcessHandler processHandler = startProcess(processStarter, patchers);
    final ConsoleView console = createAndAttachConsole(myConfig.getProject(), processHandler, executor);
    return new DefaultExecutionResult(console, processHandler, createActions(console, processHandler));
}
Also used : DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ConsoleView(com.intellij.execution.ui.ConsoleView) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 10 with ProcessHandler

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

the class PythonTask method createProcess.

/**
   * @param env environment variables to be passed to process or null if nothing should be passed
   */
public ProcessHandler createProcess(@Nullable final Map<String, String> env) throws ExecutionException {
    final GeneralCommandLine commandLine = createCommandLine();
    if (env != null) {
        commandLine.getEnvironment().putAll(env);
    }
    // To support UTF-8 output
    PydevConsoleRunner.setCorrectStdOutEncoding(commandLine, myModule.getProject());
    ProcessHandler handler;
    if (PySdkUtil.isRemote(mySdk)) {
        assert mySdk != null;
        handler = new PyRemoteProcessStarter().startRemoteProcess(mySdk, commandLine, myModule.getProject(), null);
    } else {
        EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(commandLine);
        handler = PythonProcessRunner.createProcessHandlingCtrlC(commandLine);
        ProcessTerminatedListener.attach(handler);
    }
    return handler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

ProcessHandler (com.intellij.execution.process.ProcessHandler)99 NotNull (org.jetbrains.annotations.NotNull)30 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)24 ExecutionException (com.intellij.execution.ExecutionException)17 Project (com.intellij.openapi.project.Project)17 ConsoleView (com.intellij.execution.ui.ConsoleView)15 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)14 ProcessEvent (com.intellij.execution.process.ProcessEvent)14 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)14 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)13 ProgramRunner (com.intellij.execution.runners.ProgramRunner)12 Nullable (org.jetbrains.annotations.Nullable)10 Executor (com.intellij.execution.Executor)9 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)7 Disposable (com.intellij.openapi.Disposable)7 RunProfile (com.intellij.execution.configurations.RunProfile)6 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)6 File (java.io.File)6 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)5 ToggleAutoTestAction (com.intellij.execution.testframework.autotest.ToggleAutoTestAction)5