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


Java Redirect类代码示例

本文整理汇总了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();
}
 
开发者ID:januslabs,项目名称:ansible-http,代码行数:27,代码来源:ProcessBuilderTests.java

示例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;
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:22,代码来源:DockerContainer.java

示例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);
	}
}
 
开发者ID:rizsi,项目名称:rcom,代码行数:26,代码来源:StreamSourceVnc.java

示例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);
}
 
开发者ID:rizsi,项目名称:rcom,代码行数:21,代码来源:StreamSinkVNC.java

示例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);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:25,代码来源:SingularityExecutorTaskLogManager.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:26,代码来源:LogViewerController.java

示例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);
        }
    }
}
 
开发者ID:allegro,项目名称:embedded-elasticsearch,代码行数:17,代码来源:ElasticSearchInstaller.java

示例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();
}
 
开发者ID:CodeFX-org,项目名称:demo-java-9,代码行数:23,代码来源:PipeProcessesAndAwaitCompletion.java

示例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();
}
 
开发者ID:ziy,项目名称:pkb,代码行数:24,代码来源:MalletWrapper.java

示例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);
}
 
开发者ID:CollapsedDom,项目名称:Stud.IP-Client,代码行数:21,代码来源:UpdateModel.java

示例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;
}
 
开发者ID:SRI-CSL,项目名称:bixie,代码行数:20,代码来源:AbstractIcTest.java

示例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;
}
 
开发者ID:SRI-CSL,项目名称:bixie,代码行数:20,代码来源:AbstractIcTest.java

示例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;
}
 
开发者ID:SRI-CSL,项目名称:bixie,代码行数:27,代码来源:AbstractIcTest.java

示例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.";
    }
 
开发者ID:jpplayer,项目名称:amstore-daemon,代码行数:17,代码来源:AmstoreResource.java

示例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);
}
 
开发者ID:platan,项目名称:varnish-exec,代码行数:21,代码来源:VarnishExec.java


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