processbuilder

Java ProcessBuilder how to get binary output from command

梦想与她 提交于 2019-12-11 12:02:09
问题 I am trying to use execute a command using ProcessBuilder. The command is supposed to write binary data on stdout. How can I get this data in my byte[] ? 回答1: This is a working example that returns true for output 1 and false for output 0 , (throws Exception in all other cases). I also added setting a working path and an environment variable, which is not required for your particular example so you can delete it. You can copy paste this code as a class, compile it to jar and run it. It is

ProcessBuilder in Java

坚强是说给别人听的谎言 提交于 2019-12-11 10:55:33
问题 I´m studing about this subject in this page, but I can´t find the solution, how can I execute programs in cmd using ProcessBuilder? I want to compress, open, delete a file with 7zip using the command line. I have this code as example, but doesn´t work, cmd starts but doesn´t create the compress file: String[] commands= {"cmd.exe", "7za", "a", "-t7z", "test.7z", "Test.txt", "/C", "start"}; ProcessBuilder pb = new ProcessBuilder(commands); 回答1: The problem is a little bit in Java (start()

Java ProcessBuilder Limits

会有一股神秘感。 提交于 2019-12-11 10:54:51
问题 I have a Java program that connects to a local server via sockets and I would like to not have to start the server manually if Java detects that it isn't running. So if Java is not connected to the server then I use a ProcessBuilder to start it: new ProcessBuilder(new String[]{"/bin/bash", "-c", "./start_server"}).start(); Which starts the server, and runs for about 4 minutes, until the server process doesn't respond. It's interesting that if I send more commands it takes less time for this

Unable to capture full output from groovy execute

让人想犯罪 __ 提交于 2019-12-11 10:49:39
问题 I am trying to list the content fo an svn folder which contains about 1200 items. Along the lines in "Execute a external program within a groovy script and capture the output", I developed the following code def svnCommand = "svn list ${repoUrl}" def sout = new StringBuilder() def serr = new StringBuilder() Process sproc = svnCommand.execute() sproc.consumeProcessOutput(sout, serr) sproc.waitForProcessOutput() println sout If I am going to run this script I always get a truncated output, no

Java ProcessBuilder Pipe [duplicate]

陌路散爱 提交于 2019-12-11 10:03:54
问题 This question already has answers here : Using Java ProcessBuilder to Execute a Piped Command (2 answers) Closed 5 years ago . I have a shell command my_command that accepts a pipe as input , eg echo "test" | my_command param1 param2 I tried this: cmd.add("echo"); cmd.add( "test"); cmd.add("| my_command"); cmd.add(param1); cmd.add(param2); but i did I not get desired result. cmd is a list declared using ArrayList . thanks 回答1: ProcessBuilder can run only programs but echo is not a program but

shp2pgsql, psql command not found through ProcessBuilder Java

一曲冷凌霜 提交于 2019-12-11 08:41:45
问题 The following command works well in command line shp2pgsql -s 4326 /Users/abc.shp | psql -U user1 -h localhost -p 5432 -d postgis However when I run the following command in Java using ProcessBuilder it says command not found. Here is the code: public static void main(String arg[]) throws Exception { ProcessBuilder pb = new ProcessBuilder("/bin/sh -c shp2pgsql /Users/abc.shp | psql -U user1 -h localhost -p 5432 -d postgis"); Process p = pb.start(); showOutput(p.getInputStream(), System.out);

ProcessBulder loads the process but doesn't start it

你离开我真会死。 提交于 2019-12-11 06:34:08
问题 I use ProcessBuilder to start a new process (child) form a java application (host). Something like this: ProcessBuilder processBuilder = createProcess(commandLine); processBuilder.directory(new File(baseDir)); processBuilder.redirectErrorStream(true); Process process = null; try { process = processBuilder.start(); } catch (Exception e) { e.printStackTrace(); } I do see in the system monitor that the child process has been started but it's not functioning unless I stop the host application.

trouble with ProcessBuilder

混江龙づ霸主 提交于 2019-12-11 05:41:36
问题 // following code works fine n open notepad... class demo { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("notepad"); pb.start(); }catch(Exception e) {System.out.print(e);} } } //however the above code throws an exception when any other system program is executed class demo { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("calculator"); pb.start(); }catch(Exception e) {System.out.print(e);} } } the above program throws

ProcessBuilder process not running

半世苍凉 提交于 2019-12-11 04:47:23
问题 I'm fairly new to ProcessBuilder and working with threads. In it's current state I have a J-Button which starts a scheduled executor service. The scheduled executor service is used to delegate a process to one of two process builders. The application is meant to record a user conversation. During the conversation, after x minutes it creates a wav and delegates it to an available process for transcription. The problem begins when the transcription class is called. The process is started and

Cannot launch ANY process in Java (ProcessBuilder process immediately returns with exit code 128)

牧云@^-^@ 提交于 2019-12-11 03:03:40
问题 I am trying to have Java execute another program, and it kept immediately erroring out with exit code 128 and nothing sent to stdout or stderr. I tried a simple "java -version" still with no luck. When I run it in a cmd window, it runs fine and this code works on similarly configured other machines (Windows Server 2003 x64, Java 1.6 update 25) When run on command line: C:\Documents and Settings\zugwalt>java -version Output: java version "1.6.0_25" Java(TM) SE Runtime Environment (build1.6.0