Search in sources :

Example 81 with ProcessHandler

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

the class PythonScriptCommandLineState method execute.

@Override
public ExecutionResult execute(Executor executor, PythonProcessStarter processStarter, final CommandLinePatcher... patchers) throws ExecutionException {
    if (myConfig.showCommandLineAfterwards() && !myConfig.emulateTerminal()) {
        if (executor.getId() == DefaultDebugExecutor.EXECUTOR_ID) {
            return super.execute(executor, processStarter, ArrayUtil.append(patchers, new CommandLinePatcher() {

                @Override
                public void patchCommandLine(GeneralCommandLine commandLine) {
                    commandLine.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_DEBUGGER).addParameterAt(1, "--cmd-line");
                }
            }));
        }
        PythonScriptWithConsoleRunner runner = new PythonScriptWithConsoleRunner(myConfig.getProject(), myConfig.getSdk(), PyConsoleType.PYTHON, myConfig.getWorkingDirectory(), myConfig.getEnvs(), patchers, PyConsoleOptions.getInstance(myConfig.getProject()).getPythonConsoleSettings());
        runner.setEnableAfterConnection(false);
        runner.runSync();
        // runner.getProcessHandler() would be null if execution error occurred
        if (runner.getProcessHandler() == null) {
            return null;
        }
        runner.getPydevConsoleCommunication().setConsoleView(runner.getConsoleView());
        List<AnAction> actions = Lists.newArrayList(createActions(runner.getConsoleView(), runner.getProcessHandler()));
        actions.add(new ShowVarsAction(runner.getConsoleView(), runner.getPydevConsoleCommunication()));
        return new DefaultExecutionResult(runner.getConsoleView(), runner.getProcessHandler(), actions.toArray(new AnAction[actions.size()]));
    } else if (myConfig.emulateTerminal()) {
        setRunWithPty(true);
        final ProcessHandler processHandler = startProcess(processStarter, patchers);
        TerminalExecutionConsole executeConsole = new TerminalExecutionConsole(myConfig.getProject(), processHandler);
        executeConsole.addMessageFilter(myConfig.getProject(), new PythonTracebackFilter(myConfig.getProject()));
        executeConsole.addMessageFilter(myConfig.getProject(), new UrlFilter());
        processHandler.startNotify();
        return new DefaultExecutionResult(executeConsole, processHandler, AnAction.EMPTY_ARRAY);
    } else {
        return super.execute(executor, processStarter, patchers);
    }
}
Also used : DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ShowVarsAction(com.jetbrains.python.console.actions.ShowVarsAction) TerminalExecutionConsole(com.intellij.terminal.TerminalExecutionConsole) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) UrlFilter(com.intellij.execution.filters.UrlFilter) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 82 with ProcessHandler

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

the class PythonTask method run.

/**
   * @param env         environment variables to be passed to process or null if nothing should be passed
   * @param consoleView console to run this task on. New console will be used if no console provided.
   */
public void run(@Nullable final Map<String, String> env, @Nullable final ConsoleView consoleView) throws ExecutionException {
    final ProcessHandler process = createProcess(env);
    final Project project = myModule.getProject();
    new RunContentExecutor(project, process).withFilter(new PythonTracebackFilter(project)).withConsole(consoleView).withTitle(myRunTabTitle).withRerun(() -> {
        try {
            // Stop process before rerunning it
            process.destroyProcess();
            if (process.waitFor(TIME_TO_WAIT_PROCESS_STOP)) {
                this.run(env, consoleView);
            } else {
                Messages.showErrorDialog(PyBundle.message("unable.to.stop"), myRunTabTitle);
            }
        } catch (ExecutionException e) {
            Messages.showErrorDialog(e.getMessage(), myRunTabTitle);
        }
    }).withStop(() -> process.destroyProcess(), () -> !process.isProcessTerminated()).withAfterCompletion(myAfterCompletion).withHelpId(myHelpId).run();
}
Also used : Project(com.intellij.openapi.project.Project) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunContentExecutor(com.intellij.execution.RunContentExecutor) ExecutionException(com.intellij.execution.ExecutionException)

Example 83 with ProcessHandler

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

the class PythonTask method runNoConsole.

/**
   * Runs task with out console
   * @return stdout
   * @throws ExecutionException in case of error. Consider using {@link com.intellij.execution.util.ExecutionErrorDialog}
   */
@NotNull
public final String runNoConsole() throws ExecutionException {
    final ProcessHandler process = createProcess(new HashMap<>());
    final OutputListener listener = new OutputListener();
    process.addProcessListener(listener);
    process.startNotify();
    process.waitFor(TIMEOUT_TO_WAIT_FOR_TASK);
    final Output output = listener.getOutput();
    final int exitCode = output.getExitCode();
    if (exitCode == 0) {
        return output.getStdout();
    }
    throw new ExecutionException(String.format("Error on python side. " + "Exit code: %s, err: %s out: %s", exitCode, output.getStderr(), output.getStdout()));
}
Also used : Output(com.intellij.execution.Output) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) OutputListener(com.intellij.execution.OutputListener) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with ProcessHandler

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

the class PyEduDebugRunner method createDebugProcess.

@NotNull
@Override
protected PyDebugProcess createDebugProcess(@NotNull XDebugSession session, ServerSocket serverSocket, ExecutionResult result, PythonCommandLineState pyState) {
    ExecutionConsole executionConsole = result.getExecutionConsole();
    ProcessHandler processHandler = result.getProcessHandler();
    boolean isMultiProcess = pyState.isMultiprocessDebug();
    String scriptName = getScriptName(pyState);
    if (scriptName != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(new File(scriptName), true);
        if (file != null) {
            int line = getBreakpointLineNumber(file, session.getProject());
            if (line != NO_LINE) {
                return new PyEduDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess, scriptName, line + 1);
            }
        }
    }
    LOG.info("Failed to create PyEduDebugProcess. PyDebugProcess created instead.");
    return new PyDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with ProcessHandler

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

the class PyDebugRunner method createConsoleCommunicationAndSetupActions.

public static void createConsoleCommunicationAndSetupActions(@NotNull final Project project, @NotNull final ExecutionResult result, @NotNull PyDebugProcess debugProcess, @NotNull XDebugSession session) {
    ExecutionConsole console = result.getExecutionConsole();
    if (console instanceof PythonDebugLanguageConsoleView) {
        ProcessHandler processHandler = result.getProcessHandler();
        initDebugConsoleView(project, debugProcess, (PythonDebugLanguageConsoleView) console, processHandler, session);
    }
}
Also used : PythonDebugLanguageConsoleView(com.jetbrains.python.console.PythonDebugLanguageConsoleView) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole)

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