use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.
the class OpenSimulatorAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
try {
final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", "Simulator.app");
final OSProcessHandler handler = new OSProcessHandler(cmd);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
if (event.getExitCode() != 0) {
final String msg = event.getText() != null ? event.getText() : "Process error - exit code: (" + event.getExitCode() + ")";
FlutterMessages.showError("Error Opening Simulator", msg);
}
}
});
handler.startNotify();
} catch (ExecutionException e) {
FlutterMessages.showError("Error Opening Simulator", FlutterBundle.message("flutter.command.exception.message", e.getMessage()));
}
}
use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.
the class System method which.
/**
* Locate a given command-line tool given its name.
*/
@Nullable
public static String which(String toolName) {
final String whichCommandName = SystemInfo.isWindows ? "where" : "which";
final GeneralCommandLine cmd = new GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withExePath(whichCommandName).withParameters(toolName);
try {
final StringBuilder stringBuilder = new StringBuilder();
final OSProcessHandler process = new OSProcessHandler(cmd);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDOUT) {
stringBuilder.append(event.getText());
}
}
});
process.startNotify();
// We wait a maximum of 2000ms.
if (!process.waitFor(2000)) {
return null;
}
final Integer exitCode = process.getExitCode();
if (exitCode == null || process.getExitCode() != 0) {
return null;
}
final String[] results = stringBuilder.toString().split("\n");
return results.length == 0 ? null : results[0].trim();
} catch (ExecutionException | RuntimeException e) {
return null;
}
}
use of com.intellij.execution.process.OSProcessHandler in project evosuite by EvoSuite.
the class IntelliJNotifier method attachProcess.
@Override
public void attachProcess(Process process) {
if (processHandler != null) {
detachLastProcess();
}
processHandler = new OSProcessHandler(process, null);
console.attachToProcess(processHandler);
processHandler.startNotify();
}
use of com.intellij.execution.process.OSProcessHandler in project Perl5-IDEA by Camelcade.
the class PerlRunProfileState method startProcess.
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
PerlRunConfiguration runProfile = (PerlRunConfiguration) getEnvironment().getRunProfile();
VirtualFile scriptFile = runProfile.getScriptFile();
if (scriptFile == null) {
throw new ExecutionException("Script file: " + runProfile.getScriptPath() + " is not exists");
}
Project project = getEnvironment().getProject();
String perlSdkPath = PerlProjectManager.getSdkPath(project, scriptFile);
String alternativeSdkPath = runProfile.getAlternativeSdkPath();
if (runProfile.isUseAlternativeSdk() && !StringUtil.isEmpty(alternativeSdkPath)) {
Sdk sdk = PerlSdkTable.getInstance().findJdk(alternativeSdkPath);
if (sdk != null) {
perlSdkPath = sdk.getHomePath();
} else {
perlSdkPath = alternativeSdkPath;
}
}
if (perlSdkPath == null) {
throw new ExecutionException("Unable to locate Perl Interpreter");
}
String homePath = runProfile.getWorkingDirectory();
if (StringUtil.isEmpty(homePath)) {
Module moduleForFile = ModuleUtilCore.findModuleForFile(scriptFile, project);
if (moduleForFile != null) {
homePath = PathMacroUtil.getModuleDir(moduleForFile.getModuleFilePath());
} else {
homePath = project.getBasePath();
}
}
assert homePath != null;
GeneralCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, perlSdkPath, scriptFile, getPerlParameters(runProfile));
String programParameters = runProfile.getProgramParameters();
if (programParameters != null) {
commandLine.addParameters(StringUtil.split(programParameters, " "));
}
String charsetName = runProfile.getConsoleCharset();
Charset charset;
if (!StringUtil.isEmpty(charsetName)) {
try {
charset = Charset.forName(charsetName);
} catch (UnsupportedCharsetException e) {
throw new ExecutionException("Unknown charset: " + charsetName);
}
} else {
charset = scriptFile.getCharset();
}
commandLine.setCharset(charset);
commandLine.withWorkDirectory(homePath);
Map<String, String> environment = calcEnv(runProfile);
commandLine.withEnvironment(environment);
commandLine.withParentEnvironmentType(runProfile.isPassParentEnvs() ? CONSOLE : NONE);
OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), charset) {
@Override
public void startNotify() {
super.startNotify();
String perl5Opt = environment.get(PerlRunUtil.PERL5OPT);
if (StringUtil.isNotEmpty(perl5Opt)) {
notifyTextAvailable(" - " + PerlRunUtil.PERL5OPT + "=" + perl5Opt + '\n', ProcessOutputTypes.SYSTEM);
}
}
};
ProcessTerminatedListener.attach(handler, project);
return handler;
}
use of com.intellij.execution.process.OSProcessHandler in project clion-embedded-arm by elmot.
the class OpenOcdComponent method startOpenOcd.
@SuppressWarnings("WeakerAccess")
public Future<STATUS> startOpenOcd(Project project, @Nullable File fileToLoad, @Nullable String additionalCommand) throws ConfigurationException {
if (project == null)
return new FutureResult<>(STATUS.FLASH_ERROR);
GeneralCommandLine commandLine = createOcdCommandLine(project, fileToLoad, additionalCommand, false);
if (process != null && !process.isProcessTerminated()) {
LOG.info("openOcd is already run");
return new FutureResult<>(STATUS.FLASH_ERROR);
}
try {
process = new OSProcessHandler(commandLine) {
@Override
public boolean isSilentlyDestroyOnClose() {
return true;
}
};
DownloadFollower downloadFollower = new DownloadFollower();
process.addProcessListener(downloadFollower);
RunContentExecutor openOCDConsole = new RunContentExecutor(project, process).withTitle("OpenOCD console").withActivateToolWindow(true).withFilter(new ErrorFilter(project)).withStop(process::destroyProcess, () -> !process.isProcessTerminated() && !process.isProcessTerminating());
openOCDConsole.run();
return downloadFollower;
} catch (ExecutionException e) {
ExecutionErrorDialog.show(e, "OpenOCD start failed", project);
return new FutureResult<>(STATUS.FLASH_ERROR);
}
}
Aggregations