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; }
@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 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("", ""); }
final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(workingDirectory); commandLine.setExePath(path); final ParametersList parametersList = commandLine.getParametersList(); parametersList.addParametersString("-c"); parametersList.addParametersString(String.valueOf(position)); process = commandLine.createProcess(); output = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); output.write(file.getText());
@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 ""; }
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); } }
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); commandLine.setExePath("cmd"); commandLine.addParameter("/c"); } else { commandLine.setExePath("/bin/sh"); commandLine.addParameter("-c"); commandLine.addParameter(command); output = new CapturingProcessHandler(commandLine.createProcess(), Charset.defaultCharset(), commandLine.getCommandLineString()).runProcess(); } catch (final ExecutionException e) { LOG.info("Failed executing " + command);
final GeneralCommandLine cmd = new GeneralCommandLine(); cmd.setExePath(dubPath); cmd.withWorkDirectory(config.getWorkingDir()); } else { cmd.withWorkDirectory(config.getProject().getBasePath()); cmd.addParameter("build"); } else if (toTest) { cmd.addParameter("test"); } else if (toRun) { cmd.addParameter("run"); cmd.addParameter("--temp-build"); cmd.addParameter("--coverage"); cmd.addParameter("--main-file"); cmd.addParameter(config.getTfMainFile()); cmd.addParameter("--rdmd"); cmd.addParameter("--force"); cmd.addParameter("--nodeps"); cmd.addParameter("--force-remove"); cmd.addParameter("--combined");
@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; }
@Nullable @Override protected Process createProcess() throws ExecutionException { String shellPath = MongoConfiguration.getInstance(getProject()).getShellPath(); GeneralCommandLine commandLine = MongoUtils.buildCommandLine(shellPath, serverConfiguration, database); notifier.notifyInfo("Running " + commandLine.getCommandLineString()); return commandLine.createProcess(); }
public static GeneralCommandLine buildCommandLine(String shellPath, ServerConfiguration serverConfiguration, MongoDatabase database) { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(shellPath); commandLine.addParameter(buildMongoUrl(serverConfiguration, database)); commandLine.addParameter("--username"); commandLine.addParameter(username); commandLine.addParameter("--password"); commandLine.addParameter(password); commandLine.addParameter("--authenticationDatabase"); commandLine.addParameter(authenticationDatabase); commandLine.addParameter("--authenticationMechanism"); commandLine.addParameter(authenticationMechanism.getMechanismName()); commandLine.setWorkDirectory(shellWorkingDir); commandLine.addParameters(shellArgumentsLine.split(" "));
@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(); }
@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; } }
GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(javaPath); commandLine.addParameters("-Dfile.encoding=UTF-8", "-Dapple.awt.UIElement=true"); commandLine.addParameters("-jar", monkeybrainsJarPath); commandLine.addParameters(parameters);
emptyList() ); generalCommandLine.addParameter(task); generalCommandLine.addParameters(taskParameters); generalCommandLine.createProcess(), generalCommandLine.getPreparedCommandLine(Platform.current()) ); handler.addProcessListener(
return; final GeneralCommandLine commandLine = new GeneralCommandLine(path); commandLine.setWorkDirectory(workingDirectory); commandLine.setRedirectErrorStream(true); final ParametersList parametersList = commandLine.getParametersList(); process = commandLine.createProcess(); LOG.info("DCD process started"); } catch (final ExecutionException e) {
@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); }
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)); }
protected GeneralCommandLine createRunInSimulatorCmd() throws ExecutionException { MonkeyParameters monkeyParameters = getMonkeyParameters(); VirtualFile child = monkeyParameters.getOutputPath().findChild(getPrgName()); if (child == null) { throw new ExecutionException("No .prg file was built, so nothing to run, searched path was " + monkeyParameters.getOutputPath() + " and prg name " + getPrgName()); } String prgPath = child.getPath(); Sdk sdk = monkeyParameters.getSdk(); String sdkBinPath = MonkeySdkType.getBinPath(sdk); String monkeydoExecutableName = SdkHelper.get(SdkHelper.MONKEYDO_CMD); String exePath = sdkBinPath + monkeydoExecutableName; GeneralCommandLine generalCommandLine = createGeneralCommandLine(sdkBinPath, exePath) .withParameters(prgPath, getConfiguration().getTargetDeviceId()); if (isForTests()) { generalCommandLine.addParameter(SdkHelper.get(SdkHelper.MONKEYDO_TEST_PARAM)); //if (testId != null) { // generalCommandLine.addParameter(testId); //} } if (getConfiguration().getProgramParameters() != null) { ParametersList parametersList = new ParametersList(); parametersList.addParametersString(getConfiguration().getProgramParameters()); generalCommandLine.addParameters(parametersList.getParameters()); } return generalCommandLine; }