本文整理了Java中java.lang.ProcessBuilder.redirectInput()
方法的一些代码示例,展示了ProcessBuilder.redirectInput()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ProcessBuilder.redirectInput()
方法的具体详情如下:
包路径:java.lang.ProcessBuilder
类名称:ProcessBuilder
方法名:redirectInput
暂无
代码示例来源:origin: jphp-group/jphp
@Signature
public WrapProcess redirectInputFromInherit() {
processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT);
return this;
}
代码示例来源:origin: jphp-group/jphp
@Signature
public WrapProcess redirectInputFromFile(File file) {
processBuilder.redirectInput(file);
return this;
}
代码示例来源:origin: jphp-group/jphp
@Signature
public WrapProcess redirectInputFromPipe() {
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
return this;
}
代码示例来源:origin: Alluxio/alluxio
private static boolean validateRemote(String node, String target, String name, CommandLine cmd)
throws InterruptedException {
System.out.format("Validating %s environment on %s...%n", target, node);
if (!Utils.isAddressReachable(node, 22)) {
System.err.format("Unable to reach ssh port 22 on node %s.%n", node);
return false;
}
// args is not null.
String argStr = String.join(" ", cmd.getArgs());
String homeDir = ServerConfiguration.get(PropertyKey.HOME);
String remoteCommand = String.format(
"%s/bin/alluxio validateEnv %s %s %s",
homeDir, target, name == null ? "" : name, argStr);
String localCommand = String.format(
"ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt %s \"bash %s\"",
node, remoteCommand);
String[] command = {"bash", "-c", localCommand};
try {
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
Process process = builder.start();
process.waitFor();
return process.exitValue() == 0;
} catch (IOException e) {
System.err.format("Unable to validate on node %s: %s.%n", node, e.getMessage());
return false;
}
}
代码示例来源:origin: bootique/bootique
protected <T> T runCommandWithExceptions(String[] command, Function<BufferedReader, T> resultParser) throws IOException, InterruptedException {
Process p = new ProcessBuilder(command)
// important to grab input from the Java process... THis provides a way for the terminal commands
// like "stty" to make sense of the calling environment...
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.start();
if (!p.waitFor(3, TimeUnit.SECONDS)) {
logger.trace(() -> "Command '" + toString(command) + "' is stuck, killing");
p.destroyForcibly();
return null;
}
if (p.exitValue() != 0) {
logger.trace(() -> "Command '" + toString(command) + "' failure. Exit code: " + p.exitValue());
return null;
}
try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
return resultParser.apply(r);
}
}
}
代码示例来源:origin: apache/nifi
builder.command(args);
builder.directory(dir);
builder.redirectInput(Redirect.PIPE);
builder.redirectOutput(Redirect.PIPE);
final File errorOut;
代码示例来源:origin: apache/metron
processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
代码示例来源:origin: pravega/pravega
/**
* Redirects the Standard In of the Process to the given Redirect.
*
* @param redirect The ProcessBuilder.Redirect to use.
* @return This object instance.
*/
public ProcessStarter stdIn(ProcessBuilder.Redirect redirect) {
this.builder.redirectInput(redirect);
return this;
}
代码示例来源:origin: stackoverflow.com
ProcessBuilder builder = new ProcessBuilder("/bin/bash");
builder.redirectInput();
Process process = builder.start();
while ((line = reader.readLine ()) != null) {
System.out.println ("Stdout: " + line);
}
代码示例来源:origin: stackoverflow.com
ProcessBuilder pb = new ProcessBuilder();
pb.redirectInput(new FileInputStream(new File(infile));
pb.redirectOutput(new FileOutputStream(new File(outfile));
pb.command(cmd);
pb.start().waitFor();
代码示例来源:origin: stackoverflow.com
File encodingFile = new File(outfile + ".encoding");
ProcessBuilder pb = new ProcessBuilder(vars.config.ffmpeg, "-i", file, "-y", "-s", width + "x" + height, "-vcodec", "libvpx", outfile); //or other command....
encodingFile.createNewFile();
pb.redirectErrorStream(true);
pb.redirectInput(ProcessBuilder.Redirect.PIPE); //optional, default behavior
pb.redirectOutput(encodingFile);
Process p = pb.start();
// if you want to wait for the process to finish
p.waitFor();
encodingFile.delete();
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-yaml-server
@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
return new ProcessCommunicationProvider(processBuilder, YamlModule.LANGUAGE_ID);
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-camel-server
@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
return new ProcessCommunicationProvider(processBuilder, CamelModule.LANGUAGE_ID);
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.ide/org.eclipse.scada.configuration.world.lib
public ProcessRunner ( final ProcessBuilder processBuilder )
{
this.processBuilder = processBuilder;
processBuilder.redirectError ( Redirect.INHERIT );
processBuilder.redirectOutput ( Redirect.INHERIT );
processBuilder.redirectInput ( Redirect.INHERIT );
}
代码示例来源:origin: com.oracle.substratevm/library-support
@Substitute
private static ProcessBuilder inheritInput(ProcessBuilder pb) throws Exception {
/* Original implementation calls this method using reflection. */
pb.redirectInput(ProcessBuilder.Redirect.INHERIT);
return pb;
}
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-test-ls-server
@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
return new ProcessCommunicationProvider(processBuilder, TestLSModule.LANGUAGE_ID);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws IOException, InterruptedException {
String command = "dir /w";
ProcessBuilder procBuilder = new ProcessBuilder(new String[]{"cmd", "/c", command});
procBuilder.redirectInput(Redirect.INHERIT);
procBuilder.redirectOutput(Redirect.INHERIT);
procBuilder.redirectError(Redirect.INHERIT);
Process p = procBuilder.start();
int ecode = p.waitFor();
System.err.println("Exit code " + ecode);
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-golang-lang-server
@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(launchScript.toString()).inheritIO();
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
return new ProcessCommunicationProvider(processBuilder, GolangModule.LANGUAGE_ID);
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-clangd-lang-server
@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(launchScript.toString()).inheritIO();
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
return new ProcessCommunicationProvider(processBuilder, ClangModule.LANGUAGE_ID);
}
代码示例来源:origin: stackoverflow.com
ProcessBuilder compileProcessBuilder = new ProcessBuilder(cmds);
// redirect all IO separately
compileProcessBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT);
compileProcessBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
compileProcessBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
// or use a convenient call for all at once (thanks VGR to mention it)
compileProcessBuilder.inheritIO();
Process compileProcess = compileProcessBuilder.start();
内容来源于网络,如有侵权,请联系作者删除!