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);
}
}
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();
}
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()));
}
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);
}
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);
}
}
Aggregations