Output of Process p=Runtime.getRuntime().exec("java filename

Runtime r=Runtime.getRuntime();
Process p=r.exec("java <filename>");
on implementing this code no exception is fired
nor there is any output on console window rather the console window
doesn't open.
can anyone help
2nd question:
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd.exe dir");
on executing it in windows xp it shows cannot open 16-bit windows application

Runtime r=Runtime.getRuntime();
Process p=r.exec("java <filename>");
InputStream is = p.getInputStream();The standard output stream of the programm, you are starting, is the input stream of your process.

Similar Messages

  • Runtime.getRuntime().exec(java test)

    Hi,
    As part of a thesis for college, I am trying to execute a test java program. The program executes okay and I can read the results okay.
    Sample code.
    process = Runtime.getRuntime().exec("java test");
    InputStream iOutStream = process.getInputStream();
    InputStream ErrorStream = process.getErrorStream();
    However, I need to be able to execute a progam that reads a parameter from the screen. I tried to pass a parameter file but it doesn't work.
    process = Runtime.getRuntime().exec("java test <input.txt");
    I also tried just passing the parameters as a string array but it doesn't work either.
    process = Runtime.getRuntime().exec("java test 2, 2");
    Is there any other way that I can get the process to accept parameters?
    My deadline is looming so any help would be greatly appreciated.
    Thanks
    Eleanor
    [email protected]

    I think you are waiting when reading the output before you write to the stream until it becomes NULL or -1. That will never finish if the program you execute is expecting input!
    See a working example:
    This class does nothing than print a line on the console, then waits for a line of input, then prints the result again on the console. This is the class you'd execute from some other java code:
    import java.io.*;
    public class Input {
        public static void main(String args[]) {
            try {
                System.out.println("Before input");
                BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
                String s=r.readLine();
                System.out.println("Got line : " + s);
            } catch(Exception e) {
                    System.out.println(e.getMessage());
    }The following 'controls' the input-test class above, so compile the classes and execute the following one:
    import java.io.*;
    import java.lang.*;
    public class test {
        public static void main(String args[]) {
            try {
                Process p = Runtime.getRuntime().exec("java Input");
                BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedWriter w = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
                String s=r.readLine(); // You cannot read until NULL because that will not happen before you have 'input' something
                System.out.println("Got: " + s);
                w.write("cvxcvxcvx\n\r");
                w.flush();
                System.out.println("waiting result:");
                while( (s=r.readLine()) != null) { // read until finished.
                    System.out.println("after : " + s);
            } catch(Exception e) {
                    System.out.println(e.getMessage());               
    }

  • Runtime.getRuntime().exec(java method); - Passing strings between methods

    Hi all,
    I am using Runtime.getRuntime().exec(java xxxxxx); to run a java program from within a java program, i also need to pass a string to the new program. Does anyone know how to do this?
    Matt

    how would i retrive those strings in myApp as i want
    to put the values from them in a JLabelYou have a main method like this, right?
    public static void main(String[] args) { ... }
    args contains the array of strings passed to the app from the command line.

  • Pls help me about Runtime.getRuntime().exec("java...")

    I have two applications. One is Client, the other is Platform.
    In the Platform, there are source files packaged into a library named ZtConfig.jar used by Client. If run Client and Platform, two applications can execute normally.
    But if Client is started by user from platform, there is something wrong.
    I noticed the error difficultly with finally catching exception.
    I was puzzled. It is so strange. Pls help me. I list some codes here.
    In Client where finally exception catched:
    import zt.config;
            try {
              xmlFileUrl = new java.net.URL(
                  "file:///e:/Client/src/config/nsr1000.xml");
            catch (IOException ex1) {
              FileLogger.error(ex1.getMessage());
            FileLogger.info("NSR1000Document.setIEDContent", xmlFileUrl.toString());
            try {
              xmlLoader = new XMLConfigLoader(xmlFileUrl);
            finally {
              FileLogger.error("NSR1000Document.setIEDContent",
                               "cannot new XMLConfigLoader object");
              return; // the following codes cannot execute, so have to return here.
    In the XMLConfigLoader, the constructor is
      public XMLConfigLoader(java.net.URL xmlFileUrl) {
        this.xmlFileUrl = xmlFileUrl;
        configDoc = null;
        builder = null;
        xmlDoc = null;
    Platform start Client application using the following code
      Runtime.getRuntime().exec(
                    "java -jar e:/Client/Client.jar");

    I've got it!
    Briefly, it is because classpath setting was overwritten by JBuilder.
    Firstly, I start Platform from JBuilder. In its messages window. The command is
    d:\j2sdk1.4.2_06\bin\javaw -classpath "JBPATH" zt.client.nsr1000.NSR1000App
    Now, classpath environment variable was changed to be JBPATH. While I start
    Client use Runtime.getRuntime().exec("java -jar Client.jar"), it will not run for classpath changed.
    Then, I configured all packages used by Client into JBuilder libraries, including
    Client.jar. And changed codes Runtime.getRuntime().exec("java -jar Client.jar") to be Runtime.getRuntime().exec("java -Xmx128m zt.client.nsr1000.NSR1000App")
    I also changed CLASSPATH windows system environment variable.
    I found this from command console, it can display exceptions. But from JBuilder, there is no exception that can be captured. So debug is difficult.

  • Process via Runtime.getRuntime().exec(), how to identify that it�s closed?

    A process(console program) is started via Runtime.getRuntime().exec() from Swing Application.
    Swing Application need to know the result of this process.
    So, is there any possibility to find whether the console program is finished?

    Runtime.exec() returns a Process object.
    Look at its methods, especially waitFor(). Read carefully the whole Process documentation, especially what has to be done with the output streams.

  • Kill "runtime.getruntime().exec"-generated processes with control-c?

    Hi there,
    In my java program I create 2 processes with "runtime.getruntime().exec", but when I stop my java program pressing control-c these 2 processes remains running and I have to kill them using linux command "kill".
    How can I program my code in order to kill these 2 processes when stopping my java program with control-c?
    I tried next but it didn't work for me:
            try {
    final Process proc = Runtime.getRuntime().exec ( "java ControlCProblemDemo" );
    Runtime.getRuntime().addShutdownHook(
    new Thread(){
    public void run(){
    proc.destroy();
    while ( true );
    } catch( IOException ioe ) {
    System.err.println( ioe );
    }Thank you very much in advance.
    Josu&eacute;

    so are you saying proc.destroy() does nothing?
    are you sure it's getting executed?
    is there an error?
    too little info here

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Runtime.getRuntime().exec hangs and doesn't print the output

    Hi,
    I have written the following code to execute the command "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt" and print the output in 25_showoutpout.txt file.
    import java.io.*;
    public class ExecTest{
         public static void main(String args[]) throws IOException{
         String args1 = "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt";
         try{
         Process p=Runtime.getRuntime().exec(args1);
    int i = p.waitFor();
         System.out.println("Done.with time "+i);
         }catch(Exception e){
              System.out.println("The error is "+e);
    But this program hangs and creates a blank 25_showoutpout.txt file.In the process list I can see the process running, but it doesn't redirect the output in the txt file.When i run the command from the command line it runs fine.Please help me.
    Thanks in advance

    Hi,
    I have written the following program to get the output.But still the required output is not coming in the console file.Only the messages that gets printed in the parent console that is coming in the file.But the expected output is to get the messages from the child window which gets executed while the .exe runs.
    import java.io.*;
    public class RuntimeExecTest{
    public static void main(String args[]){
    String s = null;
    String result= null;
    int count =0;
    try{
              // read the output from the command
    String cmd = "cmd.exe /c D:/installer/PsTools.zip/PsTools/psexec.exe ipaddress -u userid -p password -l -c excute.exe >> C:/RuntimeExec_25.txt";
         Process p = Runtime.getRuntime().exec(cmd);
         InputStream is = p.getInputStream();
         // Get the std in to the process.
         OutputStream os = p.getOutputStream();
         // Get the std err from the process.
         InputStream es = p.getErrorStream();
         // Create readers for those streams.
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         BufferedReader errReader = new BufferedReader(new InputStreamReader(es));
         String line;               
         // Read STDOUT into a buffer.
         // If no STDOUT check STDERR.
         while((line = errReader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         while((line = reader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         System.exit(0);
    catch( Exception ex )
    ex.printStackTrace();
    }

  • How to get return value from Java runtime.getRuntime.exec?

    I'm running shell commands from an Oracle db (11gr2) on aix.
    But, I would like to get a return value from a shell comand... like you get with "echo $?"
    I use a code like
    CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS
    import java.io.*;
    public class Host {
      public static int executeCommand(String command) {
        int retval=0;
        try {
            String[] finalCommand;
            finalCommand = new String[3];
            finalCommand[0] = "/bin/sh";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
       catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
          retval=-1;
        return retval;
    /but I do not get a return value... because I don't know how to get return value..
    Edited by: user9158455 on 22-Sep-2010 07:33

    Hi,
    Have your tried pr.exitValue() ?
    I think you also need a finally block that destroys the subprocess
    Regards
    Peter

  • Using Process Runtime.getRuntime().exec

    http://im1.shutterfly.com/procserv/47b4d633b3127cceb46774c84ee80000001610
    Here is a URL to a part of the current process I need to run. Actually there are 4 steps that preceed these but they are ran in order and must be done before these (that part is easy). Sorry it kinda chopped off the left side a little bit.
    My question is, can I do this entirely using Runtime.getRuntime().exec() commands or do I need to involve multi threading. The reason I am asking is because P13 cannot run until P8 and P9 completes, but that shouldn't stop the rest of the program from running.
    If I have something like
    Process P4 = Runtime.getRuntime().exec(P4);
    Process P5 = Runtime.getRuntime().exec(P2);
    // Some handling for the streams of these processes goes here
    P4.waitFor();
    P2.waitFor();
    if(P2.exitValue() != 0){
    Process P5 = Runtime.getRuntime().exec(P5);
    Process P6 = Runtime.getRuntime().exec(P6);
    // Some handling for the streams of these processes goes here
    Does that mean the whole program will stop and wait until P4 is done before even checking for P2? If P2 is finished would the program continue and run P5 and P6 even if P4 is still running or will it wait for P4 to complete also. P4 has nothing to do with P2?
    Also any advice ???

    P4 and P2 will both be running in parallel (or as much as your OS and hardware allows them to be). As soon as both are done, and regardless of which finishes first, whatever follows P2.waitFor() will execute.
    If you have multiple groups of processes, where the processes within a group must execute sequentially, but the groups themselves can run independently of each other, then you'll need to either use Java's threads, or wrap each group of sequential processes in a shell script or batch file the executes that group sequentially.
    If there are complex dependencies among the groups--that is, multiple groups must wait on the same process, or one group must wait for multiple other groups, then it might be easier to control the concurrency in Java.

  • Strange behaviour of Runtime.getRuntime().exec(command)

    hello guys,
    i wrote a program which executes some commands in commandline (actually tried multiple stuff.)
    what did i try?
    open "cmd.exe" manually (administrator)
    type "echo %PROCESSOR_ARCHITECTURE%" and hit enter, which returns me
    "AMD64"
    type "java -version" and hit enter, which returns me:
    "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    type "reg query "HKLM\SOFTWARE\7-zip"" returns me:
    HKEY_LOCAL_MACHINE\SOFTWARE\7-zip
    Path REG_SZ C:\Program Files\7-Zip\
    i wrote two functions to execute an command
    1) simply calls exec and reads errin and stdout from the process started:
    public static String execute(String command) {
              String result = "";
              try {
                   // Execute a command
                   Process child = Runtime.getRuntime().exec(command);
                   // Read from an input stream
                   InputStream in = child.getInputStream();
                   int c;
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
                   in = child.getErrorStream();
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
              } catch (IOException e) {
              return result;
         }the second function allows me to send multiple commands to the cmd
    public static String exec(String[] commands) {
              String line;
              String result = "";
              OutputStream stdin = null;
              InputStream stderr = null;
              InputStream stdout = null;
              // launch EXE and grab stdin/stdout and stderr
              try {
                   Process process;
                   process = Runtime.getRuntime().exec("cmd.exe");
                   stdin = process.getOutputStream();
                   stderr = process.getErrorStream();
                   stdout = process.getInputStream();
                   // "write" the parms into stdin
                   for (int i = 0; i < commands.length; i++) {
                        line = commands[i] + "\n";
                        stdin.write(line.getBytes());
                        stdin.flush();
                   stdin.close();
                   // clean up if any output in stdout
                   BufferedReader brCleanUp = new BufferedReader(
                             new InputStreamReader(stdout));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += line + "\n";
                   brCleanUp.close();
                   // clean up if any output in stderr
                   brCleanUp = new BufferedReader(new InputStreamReader(stderr));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += "ERR: " + line + "\n";
                   brCleanUp.close();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return result;
         }so i try to execute the commands from above (yes, i am using \\ and \" in java)
    (1) "echo %PROCESSOR_ARCHITECTURE%"
    (2) "java -version"
    (3) "reg query "HKLM\SOFTWARE\7-zip""
    the first function returns me (note that ALL results are different from the stuff above!):
    (1) "" <-- empty ?!
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    the second function returns me:
    (1) x86 <-- huh? i have AMD64
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    horray! in this version the java version is correct! processor architecture is not empty but totally incorrect and the reg query is still err.
    any help is wellcome
    note: i only put stuff here, which returns me strange behaviour, most things are working correct with my functions (using the Runtime.getRuntime().exec(command); code)
    note2: "reg query "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0" /t REG_SZ" IS working, so why are "some" queries result in ERR, while they are working if typed by hand in cmd.exe?

    ok, i exported a jar file and execute it from cmd:
    java -jar myjar.jar
    now the output is:
    (1) "" if called by version 1, possible to retrieve by version 2 (no clue why!)
    (2) "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    (3) C:\Program Files\7-Zip\
    so all three problems are gone! (but its a hard way, as i need both functions and parse a lot of text... :/ )
    thanks for the tip, that eclipse changes variables (i really did not knew this one...)

  • PROBLEM in executing a shell command through Runtime.getRuntime().exec()

    Hi all,
    I was trying to execute the following code:
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    * Created on Mar 13, 2007
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    * @author 195092
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ClassReportDeleteDaemon {
         ClassReportDeleteDaemon()
         public static void main(String[] args) throws Exception
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs;
              String strQuery = null;
              String strdaysback = null;
              String delstring = null;
              int daysback;
              try
                   System.out.println("REPORT DELETION ::: FINDING DRIVER");               
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch(Exception e)
                   System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
                   System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
              try
                   String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
                   System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
                   conn = DriverManager.getConnection(strUrl);
                   System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
                   while(true)
                        System.out.println("WHILE LOOP");
                        stmt = conn.createStatement();
                        strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
                        rs = stmt.executeQuery(strQuery);
                        while(rs.next())
                             strdaysback = rs.getString("REP_DAYS_OLD");
                             //daysback = Integer.parseInt(strdaysback);
                        System.out.print("NO of Days===>" + strdaysback);
                        delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
                        System.out.println("DELETE STRING===>" + delstring);
                        Process proc = Runtime.getRuntime().exec(delstring);
                        //Get error stream to display error messages encountered during execution of command
                        InputStream errStream=proc.getErrorStream();
                        //Get error stream to display output messages encountered during execution of command
                        InputStream inStream = proc.getInputStream();
                        InputStreamReader strReader = new InputStreamReader(errStream);
                        BufferedReader br = new BufferedReader(strReader);
                        String strLine = null;
                        while((strLine=br.readLine())!=null)
                             System.out.println(strLine);
                   }     //end of while loop
              }     //end of try
              catch (Exception e)
                   System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
                   conn.close();
         }     //end of main
    }     //end of ClassReportDeleteDaemon
    But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
    Please help.
    Thanking u.......

    Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
            String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
            final Process process = Runtime.getRuntime().exec(command);
      You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
    P.S. Why are you not using Java to find and delete these files?
    Message was edited by:
    sabre150

  • Swign application and Runtime.getRuntime().exec(cmd)

    i want to use this program in a swing application, when i press the button it will execute this comand,?? is possible?
    String[] cmd = {"pwd","ls"};
    try {
    Process ls = Runtime.getRuntime().exec(cmd);
    BufferedReader input1 = new BufferedReader(new InputStreamReader(ls.getInputStream()));
    String str = input1.readLine();
    /* Keep looping until we have read all of the output */
    while(str != null) {
    System.out.println(str);
    str = input1.readLine();
    } catch (java.io.IOException el) {
    System.err.println(el);
    import javax.swing.*;
    import java.awt.event.*;
    public class Main{
    JFrame frame;
    public static void main(String[] args){
    Main db = new Main();
    public Main(){
    frame = new JFrame("Show Message Dialog");
    JButton button = new JButton("Click Me");
    button.addActionListener(new MyAction());
    frame.add(button);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
    JOptionPane.showMessageDialog(frame,"hello");
    }

    its pretty hard to read without code tags,
    if your questions is can i use this code in my new swing applications when i press a button
    sure you can you need to make your new program with actionlisterners, your button will then wait until you click on it,
    then you will call your old method when the button is clicked
    I think that what you want sorry if i got the wrong end of the stick

  • Inconsistent exit code from Runtime.getRuntime().exec

    I'm getting non-deterministic behavior from a call to a native process. Here is the code:
    public class Test {
    public static void main (String[] pArgs) {
    try {
    String cmd[] = { "cmp", "-s",
    pArgs[0],
    pArgs[1] };
    System.err.println("running command: ");
    Process p = Runtime.getRuntime().exec(cmd);
    System.err.println("getting exitcode...");
    int exitcode = p.waitFor();
    System.err.println(exitcode);
    System.err.println(p.exitValue());
    } catch(Exception e) {
    System.err.println("Caught exception while executing cmd");
    e.printStackTrace();
    And here is the output:
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    0
    0
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    1
    1
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    0
    0
    they should all be 1's because the files are different. when i run it on the command line i get:
    bock@homeruns[~/work/index]10:13> cmp -s output output.old ; echo $?
    1
    any help would definitely be appreciated!
    thanks,
    roger

    thanks for the link. i read through it but it doesn't seem to address why the exit code would be inconsistently reported. the other problems described by that link don't seem to apply to this case because i have not experienced hanging and there is no standard input, standard output, or standard error associated with "cmp -s" - all it does is return the appropriate exit code.
    should i be reporting this as a bug to sun? up till recently i've been assuming it was a problem with my code but now i'm not so sure...

  • Runtime.getRuntime().exec question

    Hi
    I have written an program where i need to open files on my computer with specific commands, but it wont work correctly.
    It looks something like this in my Tools class:
    public void setCustomCmd (String cmd) {
              customOpenCmd = cmd;
         public void openCustom (String[] path) {          
              String[] uu = new String[path.length + 1];
              uu[0] = customOpenCmd;
              for (int i = 1;i < uu.length;i++) {
                   uu[i] = path[i - 1];
              try {
                   Process p = Runtime.getRuntime().exec(uu);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }I am trying to open an array of files with the specified command, like some movies with gmplayer. (im using linux, but it would be good to make this method platform independent). The thing is it "kind of" works. When i give an array with paths to smplayer (an frontend for mplayer) they will be added to the playlist and i can play the movies, but smplayer behaves strange. When i try to open the settings or the file info for instance, smplayer just freezes. Gmplayer also "kind of" works, until i try to close it. It will freeze and i have to kill the process. (in both cases the movie still plays, but the frontend for mplayer itself freezes).
    So far i have been able to solve every problem in my learning process of java (and programming in general) with google, but im just unable to make any progress with this problem (and i REALLY have tried everything i can think of). So, can anyone help me?
    Also, smplayer does write some output to the terminal when i run it, do i need to handle that from java somehow as well?
    Thanks in advice.

    Hah! now i managed to make it work perfectly. Here is my code (maybe its a bit ugly since I'm quite new to programming in general, but it may help someone who tries to accomplish the same thing):
    public void setCustomCmd (String cmd) {
              customOpenCmd = cmd;
         public void openCustom (String[] path) {          
              String[] uu = new String[path.length + 1];
              uu[0] = customOpenCmd;
              for (int i = 1;i < uu.length;i++) {
                   uu[i] = path[i - 1];
              RunCmd zzz = new RunCmd(uu);
              zzz.start();
         private class RunCmd extends Thread
             Process proc;
             String[] cmd;
             RunCmd(String[] cmdIn)
                cmd = cmdIn;
             public String[] getCmd() {
                  return cmd;
             public boolean setCmd(String[] cmdIn) {
                  // Don't change the command in case this thread is alive.
                  if (this.isAlive()) {
                       return false;
                  cmd = cmdIn;
                  return true;
             public void run()
                  try
                       // Execute the command in run to avoid problems in case someone forgets to call
                       // run and the process "kind of" works as an result.
                       Runtime rt = Runtime.getRuntime();
                       proc = rt.exec(cmd);
                     // any error message?
                     StreamGobbler errorGobbler = new
                         StreamGobbler(proc.getErrorStream(), "ERR");           
                     // any output?
                     StreamGobbler outputGobbler = new
                         StreamGobbler(proc.getInputStream(), "OUT");
                     // kick them off
                     errorGobbler.start();
                     outputGobbler.start();
                     // any error???
                     int exitVal = proc.waitFor();
                     log.print(customOpenCmd + ":<BR>" + "<font color=green>ExitValue: " + exitVal + "</font color=green>");
                     log.print("");
                 } catch (Throwable t)
                     t.printStackTrace();
         private class StreamGobbler extends Thread
             InputStream is;
             String type;
             OutputStream os;
             StreamGobbler(InputStream is, String type)
                 this(is, type, null);
             StreamGobbler(InputStream is, String type, OutputStream redirect)
                 this.is = is;
                 this.type = type;
                 this.os = redirect;
             public void run()
                 try
                     PrintWriter pw = null;
                     if (os != null)
                         pw = new PrintWriter(os);
                     InputStreamReader isr = new InputStreamReader(is);
                     BufferedReader br = new BufferedReader(isr);
                     String line=null;
                     while ( (line = br.readLine()) != null)
                         if (pw != null)
                             pw.println(line);
                         System.out.println(customOpenCmd + ": " + type + ">" + line);
                         // log.printNoTime(customOpenCmd + ": " + type + ">" + line); So much output, my log is 2 slow :p
                     if (pw != null)
                         pw.flush();
                 } catch (IOException ioe)
                     ioe.printStackTrace(); 
         }This executes the command and lets the program continue even if the execition still runs. I have only tried this a few times, so if i encounter problems with this code i will post the solution if i manage to find it.

Maybe you are looking for

  • Ipod keeps connecting then disconnecting

    I've tried everything possible to try to make my Ipod mini work. I can't connect it to the PC because it keeps connecting and disconnecting repeatedly. I can't restore it since I can't connect it. I've tried all the different USB ports and I've insta

  • Weirdly I am unable to reply to or send new emails during the week.

    for the past 2 weeks I have been unable to send emails via my server Talk Talk during Monday - Thursday.  A message comes up saying "Cannot send mail using server smtp.talktalk.net"   This week looks like being the same.  Mt husband has an account on

  • Integrate jsf, jboss and jasper reports

    Hi there! I've a problem with integration jboss with jasper reports and jsf. Which jasper classes do I have to place on a server and what jboss files do I need to configure? How can I run jasper report from the jsf page? Any information on this subje

  • VAT GL or withhold tax GL text (SGTXT) will be update by Vendor name automatically during posting data

    Hi, When i will execute T.code FB60 for vendor AP generate purpose then VAT GL or Withhold tax GL text (SGTXT) will be update by Vendor name automatically. Anybody there , who can help me?  Best Regards, Tariq Russel.

  • Adding metadata to thumbnail view (additional fields)

    I found the ability to add a metadata display to the thumbnail view. However, it seems like it only displays 15 or so available fields. Unfortunately it b does not include the "Title" or "Document Title" field which is the one I really want to see. i