@NotNull public static com.intellij.execution.process.ProcessOutput getProcessOutput(int timeout, @Nullable String workDir, @NotNull String exePath, @NotNull String... arguments) throws ExecutionException{ if(workDir == null || !new File(workDir).isDirectory() || !new File(exePath).canExecute()){ return new com.intellij.execution.process.ProcessOutput(); } GeneralCommandLine cmd = new GeneralCommandLine().withCharset(Charsets.UTF_8); cmd.withWorkDirectory(workDir); cmd.setExePath(exePath); cmd.addParameters(arguments); return execute(cmd, timeout); }
@NotNull public static ExtProcessOutput execAndGetFirstLine(long timeout, @NotNull String... command) { try { final Process cmdRunner = new GeneralCommandLine(command).withCharset(Charsets.UTF_8).createProcess(); ExecutorService singleTreadExecutor = Executors.newSingleThreadExecutor(); try { Future<ExtProcessOutput> cmdRunnerFuture = singleTreadExecutor.submit(new Callable<ExtProcessOutput>() { @Override public ExtProcessOutput call() throws Exception { cmdRunner.waitFor(); String stdOut = readLine(cmdRunner.getInputStream()); String stdErr = readLine(cmdRunner.getErrorStream()); return new ExtProcessOutput(stdOut, stdErr); } }); try { return cmdRunnerFuture.get(timeout, TimeUnit.MILLISECONDS); } catch (Exception e) { // Suppress } cmdRunnerFuture.cancel(true); } finally { singleTreadExecutor.shutdown(); } } catch (ExecutionException e) { // Suppress } return new ExtProcessOutput("", ""); }
@NotNull public GeneralCommandLine createCommandLine() throws ExecutionException { if (myGoRoot == null) { throw new ExecutionException("Sdk is not set or Sdk home path is empty for module"); } GeneralCommandLine commandLine = !myPtyDisabled && PtyCommandLine.isEnabled() ? new PtyCommandLine() : new GeneralCommandLine(); commandLine.setExePath(ObjectUtils.notNull(myExePath, GoSdkService.getGoExecutablePath(myGoRoot))); commandLine.getEnvironment().putAll(myExtraEnvironment); commandLine.getEnvironment().put(GoConstants.GO_ROOT, StringUtil.notNullize(myGoRoot)); commandLine.getEnvironment().put(GoConstants.GO_PATH, StringUtil.notNullize(myGoPath)); if (myVendoringEnabled != null) { commandLine.getEnvironment().put(GoConstants.GO_VENDORING_EXPERIMENT, myVendoringEnabled ? "1" : "0"); } Collection<String> paths = ContainerUtil.newArrayList(); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(commandLine.getEnvironment().get(GoConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(EnvironmentUtil.getValue(GoConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(myEnvPath, true)); commandLine.getEnvironment().put(GoConstants.PATH, StringUtil.join(paths, File.pathSeparator)); commandLine.withWorkDirectory(myWorkDirectory); commandLine.addParameters(myParameterList.getList()); commandLine.withParentEnvironmentType(myParentEnvironmentType); commandLine.withCharset(CharsetToolkit.UTF8_CHARSET); return commandLine; }
@NotNull public GeneralCommandLine createCommandLine() throws ExecutionException { GeneralCommandLine commandLine = !myPtyDisabled && PtyCommandLine.isEnabled() ? new PtyCommandLine() : new GeneralCommandLine(); commandLine.setExePath(ObjectUtils.notNull(myExePath, ObjectUtils.notNull(BallerinaSdkService .getBallerinaExecutablePath(myBallerinaPath)))); commandLine.getEnvironment().putAll(myExtraEnvironment); //Todo - Add BALLERINA_REPOSITORY // commandLine.getEnvironment().put(BallerinaConstants.BALLERINA_REPOSITORY, // StringUtil.notNullize(myBallerinaPath)); Collection<String> paths = ContainerUtil.newArrayList(); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(commandLine.getEnvironment().get( BallerinaConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(EnvironmentUtil.getValue(BallerinaConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(myEnvPath, true)); commandLine.getEnvironment().put(BallerinaConstants.PATH, StringUtil.join(paths, File.pathSeparator)); commandLine.withWorkDirectory(myWorkDirectory); commandLine.addParameters(myParameterList.getList()); commandLine.withParentEnvironmentType(myParentEnvironmentType); commandLine.withCharset(CharsetToolkit.UTF8_CHARSET); return commandLine; }
@NotNull @Override public PerlCommandLine withCharset(@NotNull Charset charset) { return (PerlCommandLine)super.withCharset(charset); }
public static GeneralCommandLine createGeneralCommandLine(String workDirectory, String exePath) { if (SystemInfo.isMac) { String macExePath = exePath; List<String> parameters = new ArrayList<>(); // .app files are opened with open command? if (exePath.endsWith(".app")) { macExePath = "open"; parameters.add(exePath); parameters.add("--args"); } return new GeneralCommandLine() .withWorkDirectory(workDirectory) .withExePath(macExePath) .withParameters(parameters) .withCharset(CharsetToolkit.UTF8_CHARSET); } return new GeneralCommandLine() .withWorkDirectory(workDirectory) .withExePath(exePath) .withCharset(CharsetToolkit.UTF8_CHARSET); } }
.withCharset(Charset.defaultCharset()) .withExePath(dmdPath) .withParameters(dmdParameters);