@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; }
public static boolean checkMongoShellPath(String mongoShellPath) throws ExecutionException { if (isBlank(mongoShellPath)) { return false; } GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(mongoShellPath); commandLine.addParameter("--version"); CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset(), commandLine.getCommandLineString()); ProcessOutput result = handler.runProcess(15 * 1000); return result.getExitCode() == 0; }
public static GeneralCommandLine buildCommandLine(String shellPath, ServerConfiguration serverConfiguration, MongoDatabase database) { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(shellPath); commandLine.addParameter(buildMongoUrl(serverConfiguration, database));
@Nullable public static String readCommandLine(@Nullable final String workingDirectory, @NotNull final String command, @NotNull final String[] params, @Nullable final String input) { final GeneralCommandLine commandLine = new GeneralCommandLine(command); if (workingDirectory != null) { commandLine.setWorkDirectory(workingDirectory); } commandLine.addParameters(params); return readCommandLine(commandLine, input); }
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); } }
private String getDmdVersion(final String sdkHome) { if (isValidSdkHome(sdkHome)) { final GeneralCommandLine cmd = new GeneralCommandLine();
private void saveSvgFile(@NotNull final String outSvgFile, @NotNull final ControlFlow flow) throws IOException, ExecutionException { String dotUtilName = SystemInfoRt.isUnix ? "dot" : "dot.exe"; File dotFullPath = PathEnvironmentVariableUtil.findInPath(dotUtilName); if (dotFullPath == null) { throw new FileNotFoundException("Cannot find dot utility in path"); } File tmpFile = FileUtil.createTempFile("control-flow", ".dot", true); FileUtil.writeToFile(tmpFile, convertControlFlowToDot(flow)); ExecUtil.execAndGetOutput(new GeneralCommandLine(dotFullPath.getAbsolutePath()).withInput(tmpFile.getAbsoluteFile()) .withParameters("-Tsvg", "-o" + outSvgFile, tmpFile.getAbsolutePath()).withRedirectErrorStream(true)); }
public static Boolean isKnownGdb(String path) { try { GeneralCommandLine command = new GeneralCommandLine(); command.setExePath(path); command.addParameter("--version"); ProcessOutput output = new CapturingProcessHandler( command.createProcess(), Charset.defaultCharset(), command.getCommandLineString()).runProcess(); if (output.getExitCode() != 0) { LOG.error("gdb exited with invalid exit code: " + output.getExitCode()); return false; } String cmdOutput = output.getStdout(); return cmdOutput.contains("(GDB) 7.6") || cmdOutput.contains("(GDB) 7.4"); } catch (Exception e) { LOG.error("Exception while executing the process:", e); return false; } }
public static String exec(@NotNull final String workDir, @NotNull final String command) { final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(workDir); commandLine.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE);
@Override protected Process createProcess() throws ExecutionException { String bashLocation = BashInterpreterDetection.instance().findBestLocation(); if (bashLocation == null) { throw new ExecutionException("Could not locate the bash executable"); } GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(getWorkingDir()); commandLine.setExePath(bashLocation); return commandLine.createProcess(); }
public static Boolean isValidGdbPath(String path) { try { GeneralCommandLine command = new GeneralCommandLine(); command.setExePath(path); command.addParameter("--version"); ProcessOutput output = new CapturingProcessHandler( command.createProcess(), Charset.defaultCharset(), command.getCommandLineString()).runProcess(); if (output.getExitCode() != 0) { LOG.error("gdb exited with invalid exit code: " + output.getExitCode()); return false; } // TODO maybe we should warn the user that his GDB version is not the latest at time of writing (7.6.2) return output.getStdout().contains("GDB"); } catch (Exception e) { // LOG.error("Exception while executing the process:", e); return false; } } }
@NotNull private GeneralCommandLine createCommandLine() { GeneralCommandLine ret = new GeneralCommandLine(); if (SystemInfo.isWindows) { ret.setExePath(ExecUtil.getWindowsShellName()); ret.addParameters("/c", GeneralCommandLine.inescapableQuote(loginSsoCmd)); } else if (SystemInfo.isMac) { ret.setExePath(ExecUtil.getOpenCommandPath()); ret.addParameters("-a", loginSsoCmd); } else { ret.setExePath("/bin/sh"); ret.addParameters("-c", loginSsoCmd); } return ret; } }
final GeneralCommandLine cmd = new GeneralCommandLine() .withWorkDirectory(config.getProject().getBasePath()) .withCharset(Charset.defaultCharset())
final GeneralCommandLine cmd = new GeneralCommandLine() .withWorkDirectory(workingDirectory) .withExePath(this.dubBinary)
@NotNull private String processFile(final PsiFile file, final String dubPath) { final GeneralCommandLine cmd = new GeneralCommandLine() .withWorkDirectory(file.getProject().getBasePath()) .withExePath(dubPath) .withEnvironment("DFLAGS", "-o-") .withParameters("build", "--combined", "-q"); try { final String dubCommand = cmd.getCommandLineString(); final DubProcessListener listener = new DubProcessListener(); final OSProcessHandler process = new OSProcessHandler(cmd.createProcess(), dubCommand); process.addProcessListener(listener); process.startNotify(); process.waitFor(); return listener.getOutput(); } catch (final ExecutionException e) { LOG.warn("There was a problem running 'dub build --combined -q'", e); } return ""; }
@NotNull public static GeneralCommandLine createCommandLine(String workingDir, BashRunConfiguration runConfig) { String interpreterPath; if (runConfig.isUseProjectInterpreter()) { interpreterPath = BashProjectSettings.storedSettings(runConfig.getProject()).getProjectInterpreter(); } else { interpreterPath = runConfig.getInterpreterPath(); } GeneralCommandLine cmd = new GeneralCommandLine(); cmd.setExePath(interpreterPath); cmd.getParametersList().addParametersString(runConfig.getInterpreterOptions()); cmd.addParameter(runConfig.getScriptName()); cmd.getParametersList().addParametersString(runConfig.getProgramParameters()); cmd.withWorkDirectory(workingDir); cmd.withParentEnvironmentType(runConfig.isPassParentEnvs() ? GeneralCommandLine.ParentEnvironmentType.CONSOLE : GeneralCommandLine.ParentEnvironmentType.NONE); cmd.withEnvironment(runConfig.getEnvs()); return cmd; }
public GeneralCommandLine getExecutableCommandLine(final DlangRunAppConfiguration config) throws ModuleNotFoundException, NoValidDlangSdkFound { final Module module = config.getConfigurationModule().getModule(); if (module == null) { throw new ModuleNotFoundException(); } final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); if (sdk == null || !(sdk.getSdkType() instanceof DlangSdkType)) { throw new NoValidDlangSdkFound(); } final VirtualFile sourcesRoot = getSourceRoot(module); final GeneralCommandLine cmd = new GeneralCommandLine(); cmd.setExePath(getOutputFilePath(module)); if (StringUtil.isNotEmpty(config.getWorkDir())) { cmd.withWorkDirectory(config.getWorkDir()); } else { cmd.withWorkDirectory(sourcesRoot.getPath()); } if (StringUtil.isNotEmpty(config.getAdditionalParams())) { cmd.addParameters(splitArguments(config.getAdditionalParams())); } return cmd; }