processbuilder

Java simple process builder issue

随声附和 提交于 2021-01-29 04:47:00
问题 I just conducted simple test code for Java Process Builder. There are 4 examples and everything is working smoothly excluding last one. Here is my codes public class bashProcessor { public static void main(String args[]) { try { ProcessBuilder pb; pb = new ProcessBuilder("/bin/bash", "-c", "touch Jin_1.sh"); pb.start(); pb = new ProcessBuilder("/bin/bash", "-c", "mkdir Jin_2"); pb.start(); pb = new ProcessBuilder("/bin/bash", "-c", "bash /home/Jin/test.sh"); pb.start(); //below is not working

Open git bash using processBuilder and execute command in it

梦想与她 提交于 2020-06-26 06:53:56
问题 Is it possible in java by using something like ProcessBuilder to open gitbash, write a command (for example git status) and output the results? I can successfully open git bash by using the following code but i don't know how to write any commands in it. String[] commands = {"cmd","/C","C:\\Users\\......\\Git\git-bash"}; ProcessBuilder builder = new ProcessBuilder(commands); builder.redirectErrorStream(true); Process process = builder.start(); StringBuilder sb = new StringBuilder();

Java ProcessBuilder ignores Whitespaces

馋奶兔 提交于 2020-05-15 08:09:49
问题 I try to start a program via the Windows command shell out of Java and experience errors I cannot solve myself. I use a ProcessBuilder to pass the arguments to the command shell. Snippet: try{ List<String> list = new ArrayList<String>(); list.add("cmd.exe"); list.add("/c"); list.add("C:\\Program Files (x86)\\TightVNC\\tvnserver.exe -controlservice -connect 172.20.242.187"); ProcessBuilder builder = new ProcessBuilder(list); System.out.println(builder.command()); builder.redirectErrorStream

Java ProcessBuilder ignores Whitespaces

蓝咒 提交于 2020-05-15 08:09:04
问题 I try to start a program via the Windows command shell out of Java and experience errors I cannot solve myself. I use a ProcessBuilder to pass the arguments to the command shell. Snippet: try{ List<String> list = new ArrayList<String>(); list.add("cmd.exe"); list.add("/c"); list.add("C:\\Program Files (x86)\\TightVNC\\tvnserver.exe -controlservice -connect 172.20.242.187"); ProcessBuilder builder = new ProcessBuilder(list); System.out.println(builder.command()); builder.redirectErrorStream

Java ProcessBuilder Cannot Find File Specified

痞子三分冷 提交于 2020-02-07 09:59:39
问题 import java.io.*; class RunTest { public static void main(String a[]) { try { String prg = "import sys\nprint int(sys.argv[1])+int(sys.argv[2])\n"; BufferedWriter out = new BufferedWriter(new FileWriter("test1.py")); out.write(prg); int number1 = 1; int number2 = 2; ProcessBuilder pb = new ProcessBuilder("python","test1.py",""+number1,""+number2); Process p = pb.start(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); int ret = new Integer(in.readLine())

Spawning multiple process using process builder from Java

限于喜欢 提交于 2020-02-05 04:13:06
问题 I am developing a web application in which I am using Java as my front end and shell as my back end . I am processing lot of files in shell .. for instance if I have to process 100 files . I am planning to spawn 4 sub processes from Java application. I read about process Builder . But I am not getting a clear idea of how to use the start() method to spawn multiple processes and then wait for all of them until it is done and again continuing processing . Any ideas reagrding this would be

How to make Redirect.INHERIT and System.setOut work together

ぐ巨炮叔叔 提交于 2020-02-04 01:29:29
问题 This may be a trivial question but I can't easily find an answer. I've got a simple program in Java: System.setOut(new PrintStream(new File("stdout.txt"))); ... ... ProcessBuilder pb = new ProcessBuilder("... some args ..."); pb.inheritIO(); pb.start().waitFor(); My intention is to store all output of the process (including child pb ) in the stdout.txt . But, this seem not to work and the output of pb is redirected to my process parent's standard output as if System.setOut(...) was never