当前位置: 首页>>代码示例>>Java>>正文


Java Redirect.PIPE属性代码示例

本文整理汇总了Java中java.lang.ProcessBuilder.Redirect.PIPE属性的典型用法代码示例。如果您正苦于以下问题:Java Redirect.PIPE属性的具体用法?Java Redirect.PIPE怎么用?Java Redirect.PIPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.lang.ProcessBuilder.Redirect的用法示例。


在下文中一共展示了Redirect.PIPE属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRedirect

/**
 * Returns a {@link java.lang.ProcessBuilder.Redirect} appropriate for the parameters. If a file
 * redirected to exists, deletes the file before redirecting to it.
 */
private Redirect getRedirect(StreamAction action, File file) {
  switch (action) {
    case DISCARD:
      return Redirect.to(new File("/dev/null"));

    case REDIRECT:
      // We need to use Redirect.appendTo() here, because on older Linux kernels writes are
      // otherwise not atomic and might result in lost log messages:
      // https://lkml.org/lkml/2014/3/3/308
      if (file.exists()) {
        file.delete();
      }
      return Redirect.appendTo(file);

    case STREAM:
      return Redirect.PIPE;

    default:
      throw new IllegalStateException();
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:25,代码来源:JavaSubprocessFactory.java

示例2: RedirectInfo

RedirectInfo() {
    this.hasRedirects = false;
    this.inputRedirect = Redirect.PIPE;
    this.outputRedirect = Redirect.PIPE;
    this.errorRedirect = Redirect.PIPE;
    this.mergeError = false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:CommandExecutor.java

示例3: getStdoutRedirect

protected Redirect getStdoutRedirect(boolean showStdout) {
    return showStdout ? Redirect.INHERIT : Redirect.PIPE;
}
 
开发者ID:Microsoft,项目名称:azure-maven-plugins,代码行数:3,代码来源:RunMojo.java

示例4: start

static Process start(String cmdarray[],
                     java.util.Map<String,String> environment,
                     String dir,
                     ProcessBuilder.Redirect[] redirects,
                     boolean redirectErrorStream)
    throws IOException
{
    String envblock = ProcessEnvironment.toEnvironmentBlock(environment);

    FileInputStream  f0 = null;
    FileOutputStream f1 = null;
    FileOutputStream f2 = null;

    try {
        long[] stdHandles;
        if (redirects == null) {
            stdHandles = new long[] { -1L, -1L, -1L };
        } else {
            stdHandles = new long[3];

            if (redirects[0] == Redirect.PIPE)
                stdHandles[0] = -1L;
            else if (redirects[0] == Redirect.INHERIT)
                stdHandles[0] = fdAccess.getHandle(FileDescriptor.in);
            else {
                f0 = new FileInputStream(redirects[0].file());
                stdHandles[0] = fdAccess.getHandle(f0.getFD());
            }

            if (redirects[1] == Redirect.PIPE)
                stdHandles[1] = -1L;
            else if (redirects[1] == Redirect.INHERIT)
                stdHandles[1] = fdAccess.getHandle(FileDescriptor.out);
            else {
                f1 = newFileOutputStream(redirects[1].file(),
                                         redirects[1].append());
                stdHandles[1] = fdAccess.getHandle(f1.getFD());
            }

            if (redirects[2] == Redirect.PIPE)
                stdHandles[2] = -1L;
            else if (redirects[2] == Redirect.INHERIT)
                stdHandles[2] = fdAccess.getHandle(FileDescriptor.err);
            else {
                f2 = newFileOutputStream(redirects[2].file(),
                                         redirects[2].append());
                stdHandles[2] = fdAccess.getHandle(f2.getFD());
            }
        }

        return new ProcessImpl(cmdarray, envblock, dir,
                               stdHandles, redirectErrorStream);
    } finally {
        // In theory, close() can throw IOException
        // (although it is rather unlikely to happen here)
        try { if (f0 != null) f0.close(); }
        finally {
            try { if (f1 != null) f1.close(); }
            finally { if (f2 != null) f2.close(); }
        }
    }

}
 
开发者ID:Java8-CNAPI-Team,项目名称:Java8CN,代码行数:63,代码来源:ProcessImpl.java

示例5: runCommand

public List<String> runCommand(final List<String> command, final Redirect redirectOutput, final Set<Integer> acceptableExitCodes) throws InterruptedException, ProcessFailedException {
  final ProcessBuilder processBuilder = new ProcessBuilder(command);

  Optional<Integer> exitCode = Optional.absent();

  Optional<OutputReader> reader = Optional.absent();

  String processToString = getCurrentProcessToString();

  try {
    processBuilder.redirectError(Redirect.INHERIT);
    processBuilder.redirectOutput(redirectOutput);

    final Process process = startProcess(processBuilder);

    processToString = getCurrentProcessToString();

    if (redirectOutput == Redirect.PIPE) {
      reader = Optional.of(new OutputReader(process.getInputStream()));
      reader.get().start();
    }

    exitCode = Optional.of(process.waitFor());

    if (reader.isPresent()) {
      reader.get().join();

      if (reader.get().error.isPresent()) {
        throw reader.get().error.get();
      }
    }

  } catch (InterruptedException ie) {
    signalKillToProcessIfActive();

    throw ie;
  } catch (Throwable t) {
    getLog().error("Unexpected exception while running {}", processToString, t);

    signalKillToProcessIfActive();

    throw Throwables.propagate(t);
  } finally {
    processFinished(exitCode);
  }

  if (exitCode.isPresent() && !acceptableExitCodes.contains(exitCode.get())) {
    throw new ProcessFailedException(String.format("Got unacceptable exit code %s while running %s", exitCode, processToString));
  }

  if (!reader.isPresent()) {
    return Collections.emptyList();
  }

  return reader.get().output;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:56,代码来源:SimpleProcessManager.java

示例6: execute

@Override
public void execute() throws MojoExecutionException {
  //
  // Say hello to the world, my little constructor injected component!
  //
  //component.hello();

  final List<String> command = new ArrayList<>();
  command.add(getCanonicalPath(_execLocation, "exec"));

  getLog().debug(String.format("args=%s", _args));

  if (!_args.isEmpty()) {
    command.addAll(_args);
  }

  if (!_fileSets.isEmpty()) {
    getLog().debug(String.format("fileSets=%s", _fileSets));
    quoteList(getResourceFiles(_fileSets, _followLinks, _allowDuplicates, _allowFiles, 
        _allowDirs), 
        command);
  }

  if (_systemCommand) {
    convertToSystemCommandArgs(command, _argQuote);
  }

  getLog().debug(String.format("command=%s", command));
  Redirect errorRedirect;

  // if (!getCanonicalPath(_errorFile, "_errorFile").isEmpty()) {
  if (_errorFile != null) {
    _errorFile = getCanonicalFile(_errorFile, "_errorFile");
    errorRedirect = _errorAppend ? Redirect.appendTo(_errorFile) : Redirect.to(_errorFile);
  } else if (!_errorProperty.isEmpty()) {
    throw new MojoExecutionException("_errorProperty currently unsupported");
  } else if (_errorInherit) {
    errorRedirect = Redirect.INHERIT;
  } else if (_errorPipe) {
    errorRedirect = Redirect.PIPE;
  } else {
    throw new MojoExecutionException(
        "must specify one of these: _errorProperty, _errorFile, _errorPipe, _errorInherit");
  }

  Redirect outRedirect;

  // if (!getCanonicalPath(_outFile, "_outFile").isEmpty()) {
  if (_outFile != null) {
    _outFile = getCanonicalFile(_outFile, "_outFile");
    outRedirect = _outAppend ? Redirect.appendTo(_outFile) : Redirect.to(_outFile);
  } else if (_outInherit) {
    outRedirect = Redirect.INHERIT;
  } else if (_outPipe) {
    outRedirect = Redirect.PIPE;
  } else if (!_outProperty.isEmpty()) {
    throw new MojoExecutionException("_outProperty currently unsupported");
  } else {
    throw new MojoExecutionException(
        "must specify one of these: _outProperty, _outFile, _outPipe, _outInherit");
  }

  _exitCode =
      createProcess(command, errorRedirect, outRedirect, _workDir, _environment,
          _redirectErrorStream);
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:66,代码来源:ExecMojo.java


注:本文中的java.lang.ProcessBuilder.Redirect.PIPE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。