Search code examples
javaubuntuprocessbuilder

Java ProcessBuilder in Ubuntu


Basically I want to open a bash file in directory /home/linux/src named i that is executable file in java using Netbeans.. When I press a button in Java file it will open the bash file..

Process p = null;
ProcessBuilder pb = new ProcessBuilder("i");
pb.directory("/home/linux/src");
p = pb.start();

any idea ?


Solution

  • If you have a look at the API you will see that ProcessBuilder takes a File as a parameter not a String.

    try

    pb.directory(new File("/home/linux/src"));
    

    Also

    ProcessBuilder pb = new ProcessBuilder("./i"); 
    

    if . is not in you path (good idea)