本文整理汇总了Java中java.lang.ProcessBuilder.Redirect类的典型用法代码示例。如果您正苦于以下问题:Java Redirect类的具体用法?Java Redirect怎么用?Java Redirect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Redirect类属于java.lang.ProcessBuilder包,在下文中一共展示了Redirect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: login
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
@Ignore
public void login() throws Exception {
List<String> commands = new ArrayList<>();
commands.add("ssh");
// commands.add("-t");
// commands.add ("-o StrictHostKeyChecking=no");
commands.add("[email protected]");
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(commands);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
processBuilder.redirectOutput(Redirect.PIPE);
processBuilder.redirectInput(Redirect.PIPE);
processBuilder.redirectError(Redirect.PIPE);
String passwd = "fortis90";
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
writer.write(passwd, 0, passwd.length());
writer.newLine();
writer.close();
Integer exitStatus = process.waitFor();
System.out.println(exitStatus);
process.destroy();
}
示例2: dumpDatabase
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
@Override
public boolean dumpDatabase(Path path, boolean compress)
{
ProcessBuilder p = Exec.build(machineenv, "docker", "exec", name, "pg_dumpall", "-U", "postgres", "-c");
p.redirectOutput(Redirect.appendTo(path.toFile()));
int ret = Exec.execit(p, null);
if ((ret == 0) && compress) {
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(path.toFile()+".zip"));
out.putNextEntry(new ZipEntry(path.getFileName().toString()));
FileInputStream in = new FileInputStream(path.toFile());
IOUtils.copy(in, out);
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
Files.deleteIfExists(path);
} catch (Exception ioe) {
log.log(Level.INFO, "Unable to compress database backup: " + ioe, ioe);
}
}
return ret == 0;
}
示例3: start
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
public void start(Client client, String streamName) throws IOException {
conn=client.conn;
oss=new OutputStreamSender(client.getMultiplexer(), StreamShareVNC.bufferSize, true);
try(ServerSocket ss=new ServerSocket())
{
ss.bind(new InetSocketAddress("localhost", 0));
int localport=ss.getLocalPort();
System.out.println("Local port: "+localport);
params=new StreamParametersVNC(streamName, client.id);
StreamDataDuplex data=(StreamDataDuplex)client.conn.shareStream(oss.getId(), params);
isr=new InputStreamReceiver(StreamShareVNC.bufferSize, true);
client.getMultiplexer().register(isr, data.backChannel);
ChainList<String> command=new ChainList<>(client.getArgs().program_x11vnc,"-connect", "localhost:"+localport);
//command.addcs("-clip", "200x200+50+50");
command.add("-localhost");
new ProcessBuilder(command).redirectError(Redirect.INHERIT)
.redirectOutput(Redirect.INHERIT)
.start();
s=ss.accept();
os=new LogFilterOutpurStream(s.getOutputStream());
System.out.println("CONNECTED!");
ConnectStreams.startStreamThread(s.getInputStream(), oss.os);
ConnectStreams.startStreamThread(isr.in, os);
}
}
示例4: start
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
@Override
public void start(AbstractRcomArgs args, IVideocomConnection conn, IMultiplexer multiplexer)
throws Exception {
int n=9;
int port=5900+n;
try(ServerSocket ss=new ServerSocket())
{
ss.bind(new InetSocketAddress("localhost", port));
ChainList<String> command=new ChainList<>(args.program_vncviewer, "-ViewOnly", "localhost:"+n);
p=new ProcessBuilder(command).redirectError(Redirect.INHERIT).redirectOutput(Redirect.INHERIT).start();
s=ss.accept();
}
oss=new OutputStreamSender(multiplexer, StreamShareVNC.bufferSize, true);
StreamDataDuplex stream=(StreamDataDuplex)conn.registerStream(streamParametersVNC.name, oss.getId());
isr=new InputStreamReceiver(StreamShareVNC.bufferSize, true);
isr.register(multiplexer, stream.backChannel);
conn.launchStream(streamParametersVNC.name);
ConnectStreams.startStreamThread(isr.in, s.getOutputStream());
ConnectStreams.startStreamThread(s.getInputStream(), oss.os);
}
示例5: copyLogTail
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
private void copyLogTail() {
if (configuration.getTailLogLinesToSave() <= 0) {
return;
}
final Path tailOfLogPath = taskDefinition.getTaskDirectoryPath().resolve(configuration.getServiceFinishedTailLog());
if (Files.exists(tailOfLogPath)) {
log.debug("{} already existed, skipping tail", tailOfLogPath);
return;
}
final List<String> cmd = ImmutableList.of(
"tail",
"-n",
Integer.toString(configuration.getTailLogLinesToSave()),
taskDefinition.getServiceLogOut());
try {
new SimpleProcessManager(log).runCommand(cmd, Redirect.to(tailOfLogPath.toFile()));
} catch (Throwable t) {
log.error("Failed saving tail of log {} to {}", taskDefinition.getServiceLogOut(), configuration.getServiceFinishedTailLog(), t);
}
}
示例6: createProcessBuilder
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
/**
* Create a process builder to launch the log viewer
* @param logDirectory
* @return
*/
protected ProcessBuilder createProcessBuilder() {
ProcessBuilder pb = new ProcessBuilder(
Paths.get(System.getProperty("user.dir"), "/bin/storm").toString(),
"logviewer",
"-c",
"storm.log.dir=" + System.getenv("MESOS_SANDBOX") + "/logs",
"-c",
Config.LOGVIEWER_PORT + "=" + port
);
// If anything goes wrong at startup we want to see it.
Path logPath = Paths.get(System.getenv("MESOS_SANDBOX"), "/logs");
if (!logPath.toFile().exists() && !logPath.toFile().mkdirs()) {
throw new RuntimeException("Couldn't create log directory");
}
File log = Paths.get(System.getenv("MESOS_SANDBOX"), "/logs/logviewer-startup.log").toFile();
pb.redirectErrorStream(true);
pb.redirectOutput(Redirect.appendTo(log));
return pb;
}
示例7: installPlugins
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
private void installPlugins() throws IOException, InterruptedException {
File pluginManager = pluginManagerExecutable();
setExecutable(pluginManager);
for (InstallationDescription.Plugin plugin : installationDescription.getPlugins()) {
logger.info("> " + pluginManager + " install " + plugin.getExpression());
ProcessBuilder builder = new ProcessBuilder();
builder.redirectOutput(Redirect.INHERIT);
builder.redirectError(Redirect.INHERIT);
builder.command(prepareInstallCommand(pluginManager, plugin));
Process process = builder.start();
if (process.waitFor() != 0) {
throw new EmbeddedElasticsearchStartupException("Unable to install plugin: " + plugin);
}
}
}
示例8: main
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
ProcessBuilder ls = new ProcessBuilder()
.command("tree", "-i")
.directory(Paths.get("/home/nipa").toFile());
ProcessBuilder grepPdf = new ProcessBuilder()
.command("grep", "pdf")
.redirectOutput(Redirect.INHERIT);
List<Process> lsThenGrep = ProcessBuilder.startPipeline(asList(ls, grepPdf));
System.out.println("Started processes...");
CompletableFuture[] lsThenGrepFutures = lsThenGrep.stream()
// onExit returns a CompletableFuture<Process>
.map(Process::onExit)
.map(processFuture -> processFuture.thenAccept(
process -> System.out.println("Process " + process.getPid() + " finished.")))
.toArray(CompletableFuture[]::new);
// wait until all processes are finished
CompletableFuture
.allOf(lsThenGrepFutures)
.join();
}
示例9: createCrfModel
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
public static void createCrfModel(String featFilepath, String modelFilepath,
String modelPrintFilepath)
throws IOException, InterruptedException, ClassNotFoundException {
// preparation
File featFile = new File(featFilepath);
File modelFile = new File(modelFilepath);
List<String> trainCommand = Arrays.asList("java", "-cp", "mallet.jar:mallet-deps.jar",
"cc.mallet.fst.SimpleTagger", "--train", "true", "--model-file",
modelFile.getAbsolutePath(), "--weights", "sparse", "--fully-connected", "false",
featFile.getAbsolutePath());
File commandDir = new File("mallet-2.0.7");
// execute train
Process trainProcess = new ProcessBuilder(trainCommand).directory(commandDir)
.redirectError(Redirect.INHERIT).start();
trainProcess.waitFor();
// read model
@SuppressWarnings("resource")
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modelFile));
CRF crf = (CRF) ois.readObject();
PrintWriter out = new PrintWriter(modelPrintFilepath);
crf.print(out);
out.close();
}
示例10: launchAndExit
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
/**
* Restarts the StudIP Client.
*/
public void launchAndExit() {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
// Start Updater
ProcessBuilder pb = new ProcessBuilder("java", "-Dname=StudIP_Client", "-jar", clientApp);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
try {
pb.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}));
System.exit(0);
}
示例11: compileJavaFile
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
protected File compileJavaFile(File sourceFile) throws IOException {
final File tempDir = getTempDir();
final String javac_command = String.format("javac -g -cp %s %s -d %s", System.getProperty("java.class.path"),
sourceFile.getAbsolutePath(), tempDir.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder(javac_command.split(" "));
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
return tempDir;
}
示例12: compileJavaFile
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
protected File compileJavaFile(File sourceFile) throws IOException {
final File tempDir = getTempDir();
final String javac_command = String.format("javac -g %s -d %s",
sourceFile.getAbsolutePath(), tempDir.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder(javac_command.split(" "));
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
return tempDir;
}
示例13: compileJavaFiles
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
protected File compileJavaFiles(File[] sourceFiles) throws IOException {
final File tempDir = getTempDir();
StringBuilder sb = new StringBuilder();
for (File f : sourceFiles) {
sb.append(f.getAbsolutePath());
sb.append(" ");
}
final String javac_command = String.format("javac -g -d %s %s",
tempDir.getAbsolutePath(), sb.toString());
System.out.println(javac_command);
ProcessBuilder pb = new ProcessBuilder(javac_command.split(" "));
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
return tempDir;
}
示例14: restartAmbari
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
@GET
@Path("/restart-ambari")
@Produces(MediaType.TEXT_PLAIN)
public String restartAmbari() throws IOException {
ProcessBuilder p = new ProcessBuilder();
// p.command("/etc/init.d/ambari-server", "restart");
p.command("/bin/bash", "/usr/lib/amstore-daemon/ambari-restarter.sh");
p.redirectOutput(Redirect.appendTo(new File(
"/var/log/amstore-daemon.log")));
p.redirectErrorStream(true);
p.start();
// Runtime.getRuntime().exec("/etc/init.d/ambari-server restart");
return "Ambari restart initiated.";
}
示例15: start
import java.lang.ProcessBuilder.Redirect; //导入依赖的package包/类
/**
* @throws UncheckedIOException if an I/O error occurs. This can happen if cannot run varnishd because of invalid varnishd command path.
*/
public VarnishProcess start(VarnishCommand command) {
String[] commandArray = command.asArray();
processBuilder.command(commandArray);
processBuilder.redirectOutput(Redirect.INHERIT).redirectError(Redirect.INHERIT);
System.out.println("Starting varnish using command: " + Arrays.stream(commandArray).collect(joining(" ")));
Process process = start(processBuilder);
try {
do {
sleep();
} while (!listeningOrCrashed(command.getAddress(), process));
} catch (InterruptedException e) {
killProcess(process);
Thread.currentThread().interrupt();
return null;
}
return new VarnishProcess(process, command);
}