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