processbuilder

Process Builder waitFor() issue and Open file limitations

I have inherited some code: Process p = new ProcessBuilder("/bin/chmod", "777", path).start(); p.waitFor(); Basically, there is for some ancient and highly voodoo based reason for storing key/value pairs on disk as files. I don't really want to go into it. However, I am left with a bunch of IO exceptions: Exception :Cannot run progra...

Using threads and ProcessBuilder

I am really unfamiliar with working with threads, so I was hoping someone could help me figure out the best way to do this. I have a JButton in my java application...when you click on the button, I have a Process Builder that creates a process which executes some external python code. The python code generates some files, and this can t...

Run Executable In Jar With ProcessBuilder

I have an application I've built that uses a non-Java executable that it calls via ProcessBuilder: ProcessBuilder pb = new ProcessBuilder(invocation); pb.redirectErrorStream(true); Process proc = pb.start(); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedRead...

Sharing objects across Java processes

I am executing another JVM (java.exe) from the main application. Is there any way to share an object (rather large object) with the newly created process (at the time of creation or after it was created). someObject sO= new someObject(); //sO is populated //Creating new process Runtime rt = Runtime.getRuntime(); Process proc = rt.exe...

Java ProcessBuilder: external process hangs

I'm using Java's ProcessBuilder class to run an external process. The process should not terminate before the Java program does; it must stay alive in command/response mode. I know that the process streams may easily 'jam' if neglected, so I've done the following: The program reads the process's combined output and error streams in a "r...

Java ProcessBuilder showing console of started java application?

I have a JAVA application that launches (using ProcessBuilder) another JAVA application like this: String val = "something"; ProcessBuilder processBuilder = new ProcessBuilder("java", "-classpath", dir, appName, val); Process p = processBuilder.start(); Now, this works fine, appName is launched with the parameter val and it runs and w...

Running a bash script from the JVM

I'm having trouble running a simple bash script from Java. Specifically: ... try{ ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", command); pb.directory(new File(dir)); Process shell = pb.start(); int exitVal = shell.waitFor(); ... where 'command' the absolute path to a bash script that is executable by all and 'dir' is th...

GWT + ProcessBuilder

Hi all, Is it possible to use ProcessBuilder with GWT? When I declare an instance of a new ProcessBuilder, I get: java.lang.ProcessBuilder is not supported by Google App Engine's Java runtime environment ...

Running Command via Java ProccesBuilder Different to Running the same in the Shell

I'm tearing my hair out trying to work out why the command I'm executing via Java using a ProcessBuilder & Process is not working. I run the "same" command at the Windows command line and it works as expected. It must be that they're not the same but I can't for the life of me work out why. The command is this: ccm start -nogui -m -q -...

What can cause Java to keep running after System.exit()?

I have a Java program which is being started via ProcessBuilder from another Java program. System.exit(0) is called from the child program, but for some of our users (on Windows) the java.exe process associated with the child doesn't terminate. The child program has no shutdown hooks, nor does it have a SecurityManager which might stop ...

powermock : ProcessBuilder redirectErrorStream giving nullPointerException

I am using powermock to mock some native command invocation using process builder. the strange thing is these test pass sometimes and fail sometimes giving a NPE. Is this a powermock issue or some gotcha in the program. the snippet of the class under test is.. public void method1(String jsonString, String filename) { try { ...

Process requires redirected input

I have a UNIX native executable that requires the arguments to be fed in like this prog.exe < foo.txt. foo.txt has two lines: bar baz I am using java.lang.ProcessBuilder to execute this command. Unfortunately, prog.exe will only work using the redirect from a file. Is there some way I can mimic this behavior in Java? Of course, ...

Correct Usage of ProcessBuilder

After researching I have noticed that the "correct" way to use java's ProcessBuilder is to spawn two other threads to manage gobbling up the stdout/stderr of the newly created process so that it doesn't hang as is shown here : javaworld article But this has left me wondering about 2 questions- 1.) Why exactly are seperate processes nee...

Java: ProcessBuilder Changing the path

I'm writing a Java program that's supposed to be the GUI frontend that utilizes a tertiary C program to generate some values for various labels. But I don't want have to hard code the path to the C program. I just want the Java Program to execute the C program on the assumption that it'll be in the same directory that I had run the Jav...

Java ProcessBuilder: Resultant Process Hangs

I've been trying to use Java's ProcessBuilder to launch an application in Linux that should run "long-term". The way this program runs is to launch a command (in this case, I am launching a media playback application), allow it to run, and check to ensure that it hasn't crashed. For instance, check to see if the PID is still active, an...

Java - How to Give method an array

I have a method like the following: public void launch(String cmd, String [] args, String workingDir) Inside this method I call ProcessBuilder. How can I call ProcessBuilder including an arbitrary number of args included in my args parameter? E.g., something like this: ProcessBuilder pb = new ProcessBuilder(cmd, args); I notice...

Executing another application from Java

I need to execute a batch file which executes another Java application. I don't care whether it executes successfully or not and I don't have to capture any errors. Is it possible to do this with ProcessBuilder? What are the consequences if I do not capture errors? However, my requirement is just to execute another Java application. ...

using Process.exec

I want to execute a batch file (this will start another java app) in the middle of my program. I dont want to wait or see whether it executed successfully nor I wanted to capture erros from executing that batch file. After I started that batch file , I want to do other stuff rather than waiting for it after i execute that batch. Do I ne...

java processbuilder/rt.exec questions

Lets say I have 2 individual java applications javaapp1 and javaapp2. from javaapp1, I am executing a .bat file (which is responsible for starting javaapp2). javaaap1 and javaapp2 are independent to eachother. Suppose I am doing it with process.exec or processbuilder. Now my question is: What does exitCode means in this case if its ...

process.exec not returning correct code

I have a Java program with code: public class Test1 { public static void main(String args[]) throws InterruptedException, IOException { String cmd = "cmd /c start test.bat"; Process p = Runtime.getRuntime().exec(cmd); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(st...