Runtime.exec failure in applet(IE and Netscape)

Hi
Runtime.exec() failures to execute an executable(VB) in an Applet with Internet Explorer and Netscape Navigator. But the same is working fine with Mozilla Firefox and Opera. All the four browsers can load the applet successfully and listens the Swing component's action by actionlistener. But the problem is that IE and Netscape cant execute a VB created executable. The sample code of failure part is:
public void actionPerformed(java.awt.event.ActionEvent e){
Runtime.getRuntime().exec(abc.exe);
Here abc.exe is a VB exe for doing simple thing.
Plz help me on it if anyone knows about it..................
Raz
Message was edited by:
rashidul

hi,
1st: 40MB is maybe a little bit too much :-)
2nd swing is not really good for applets and espicially not for IE
regards

Similar Messages

  • Runtime.exec() in a seperate thread, and multithreading in general

    Hey guys -
    I've scoured the web trying to learn how to make separate threads in Java, but to no avail. My situation is that I am using mplayer in Linux with my application, but the JFrame that I am using freezes after selecting the file and mplayer successfully being launched in the background and playing. The JFrame has a textbox that is trying to get the output of the command from the console using a simple BufferedReader.
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                     
               int status = musicfile_dialog.showOpenDialog(null);
               if (status == musicfile_dialog.APPROVE_OPTION)
                     File selectedFile = musicfile_dialog.getSelectedFile();
                     String[] cmd = {"mplayer", selectedFile.toString()};
                     try                        
                         int index = 0;
                         double current = 0.0;
                         double end = 0.0;
                         char[] split_up;
                         boolean output_percent = true;
                         String line;
                         Process p = Runtime.getRuntime().exec(cmd);
                         catch (InterruptedException interrupt)
                         BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                         while ((line = input.readLine()) != null)
                             split_up = line.toCharArray();
                             for(int x=0;x<line.length();x++)
                                 try{current = Double.parseDouble(String.valueOf(split_up[3]) + String.valueOf(split_up[4]) + String.valueOf(split_up[5]) + String.valueOf(split_up[6]) + String.valueOf(split_up[8])); output_percent = true;}
                                 catch (NumberFormatException numf) // happens becuase mplayer outputs some junk at very beginning of output
                                     output_percent = false;
                                 if(split_up[x]=='f')
                                     try{end = Double.parseDouble(String.valueOf(split_up[x+2]) + String.valueOf(split_up[x+3]) + String.valueOf(split_up[+4]) + String.valueOf(split_up[x+5])); output_percent = true;}
                                     catch (NumberFormatException numf2) // happens becuase mplayer outputs some junk at very beginning of output
                                         output_percent = false;
                                 if(output_percent)
                                     double percent = (current/end)*100;
                                     String display_percent = Double.toString(percent);
                                     jTextField1.setText(jTextField1.getText() + "\n" + display_percent);
                                     System.out.println(display_percent);
                         input.close();
                    catch (IOException e) { e.printStackTrace();}           
        } So essentially, I'm trying to make it so that the JFrame doesn't freeze up when given the command
    jTextField1.setText(jTextField1.getText() + "\n" + display_percent);and also so that mplayer's console output is still available to the JFrame for processing.
    Any ideas?
    Thank you so much,
    Andrew
    Edited by: AndrewTheArt on Nov 4, 2007 6:29 AM

    I've scoured the web trying to learn how to make separate threads in Java, but to no avail. Err.. the first Google hit - http://java.sun.com/docs/books/tutorial/essential/concurrency/ . Also there is a section of Threading within Swing in the Swing tutorial.

  • Runtime.exec failture

    Hi
    Runtime.exec() failures to execute an executable in an Applet with Internet Explorer taken from VB. But the same is working fine with Mozilla Firefox and Opera. The sample code of failure part is:
    public void actionPerformed(java.awt.event.ActionEvent e){
    Runtime.getRuntime().exec(abc.exe);
    Here abc.exe is a VB exe for doing simple thing.
    Plz help me on it if anyone knows about it..................
    Raz

    Thank you.
    I was hoping for an example of the use of
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[]) or
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[],%20j
    va.io.File) which take environment variable
    information such as PATH.
    The reason is because there is a library which is
    being loaded via loadLibrary (
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Syste
    .html#loadLibrary(java.lang.String) ). However, for
    the child process to find the library the PATH needs
    to be updated.
    Any example regarding changing the PATH variable via
    Java so that libraries can be loaded and processes
    created? (Perhaps, I should make a new post and
    restate the question with this more explicit
    information?)
    That won't work. LoadLibrary occurs in the JVM environment. As I said you can't change the JVM environment via exec().
    If the shared library needs something in the path then you are going to have to set the path before your application starts up.
    If you just need to load the library from someplace that is not on the path then you should be using System.load().

  • Runtime.exec with a unix shell script

    I've done a lot of google'ing and haven't found a definitive answer to my question, including the JavaWorld article that is pointed to quite often. Scenario1 - The program calling Runtime.exec is running in /dir1 and I have a script called test.sh in /dir2 (neither directory are in the path). If I call Runtime.exec("test.sh", null, "/dir2"), I get java.io.IOException: test.sh: not found. However, if I do "touch test.sh" AND "chmod +x test.sh" in /dir1 and call the same exec, it works AND runs the script in /dir2 not /dir1?!?! Also, if I copy /dir2/test.sh /dir1/test.sh and I call exec("test.sh"), it works fine. Scenario2 - If I get rid of /dir1/test.sh and call exec("/dir2/test.sh", null, "/dir2") OR exec("/bin/sh test.sh", null, "/dir2") - both of those work. I just don't get Scenario1. Why does having the dummy executable test.sh in /dir1 allow it to run in /dir2 OR if the script is in the local directory of the process calling exec, why does it work without adding the path? It doesn't seem consistent. Seems like the working directory I specify isn't set before trying to run it or something. On the flip side, if I have a java class in /dir2 called test.class, I can call exec("java test", null, "/dir2") and it just runs without jumping through any hoops - although I think the explanation for that is that "java" is in the path. Let me know what you think.
    Gary

    I think the problem is that the three argument version of exec specifies the command to run (should be full path to it if it is not in the current dir), the environment, then the working directory. The working directory will not help java to find the command to run in the first place. The following does work as you say:
    Runtime.exec("/bin/sh test.sh",null,"/dir2");This is because the full path to the command (/bin/sh) is specified, that runs in directory /dir2 then tries to find test.sh which it finds there.
    Basically to run anything, you should specify the full path in the command, the working directory will not help java find it.
    Dave

  • To jschell How to get data System properties by JNI and Runtime.exec()

    Thank you very much for answer. ummm....but I'm can not gets data system properties by JNI or Runtime.exec(). Please help me. I'm want create Java-Applet for data System properties ( memory quantity?, Harddisk capacity?, CPU speed ?, Printer Name? and all hardwares ) in my computer. It very important for me. Help me please. thank you..

    Java applets are restricted to accessing only some system properties - and it is good so. I would not be happy if any applet could inquire about, say, my user name or the amount of memory in my box.

  • Runtime.exec() returns exitValue wrongly on windows XP and Windows 200

    I am trying to execute a batch script from java program using runtime.exec(). I then process exit code for any failures. I see that exit code is always 0 in case of windows XP and Windows 2000. But the same code and script when executed on windows 2003 or unix gives appropriate exit code. Is there any issue with Windows XP and Windows 2000?
    Thanks,
    Sandeep

    I am trying to execute a batch script from java program using runtime.exec(). I then process exit code for any failures. I see that exit code is always 0 in case of windows XP and Windows 2000. But the same code and script when executed on windows 2003 or unix gives appropriate exit code. Is there any issue with Windows XP and Windows 2000?
    Thanks,
    Sandeep

  • Using Runtime exec() to open and close process like java or javac

    Hi, I m a student who is learning IT and is wondering if
    Runtime exec() can run and stop commands like java and javac?
    Can someone post the code to do so here?Thank you

    Well, Here is my complete code:
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    class Program implements Runnable
         Process proc;
    String args[];
         String[] cmd = new String[4];
         boolean isGone=false;
         public Program(String args[])
              this.args=args;
         public void run()
              if (isGone==true)
                   try
                        Runtime.getRuntime().exec(cmd).destroy();
                   catch(IOException e)
                        System.out.println("Error: "+e.toString());
                   System.out.println("User abort");
         public void start(String args[])
              if (args.length < 1)
    System.out.println("USAGE: java GoodWindowsExec <cmd>");
    System.exit(1);
    try
    String osName = System.getProperty("os.name" );
    if( osName.equals( "Windows NT" ) )
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[3] = args[0];
    else if( osName.equals( "Windows 95" ) ||osName.equals( "Windows 98" ))
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
                        cmd[3]=args[1];
    Runtime rt = Runtime.getRuntime();
    // System.out.println("Execing " + cmd[0] + " " + cmd[1]
    // + " " + cmd[2]+" "+args[1]);                                    
    proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    // int exitVal = proc.waitFor();
    //System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
         public void destroy()
              isGone=true;
    class test1 implements ActionListener
         String s[]={"c:\\jdk1.3\\bin\\java.exe","ContactProcessor1"};
         GUI g=new GUI();
              Program p=new Program(s);
         public test1()
              //didnt work
              g.getStart().addActionListener(this);
              g.getStop().addActionListener(this);
              g.show();
         public void actionPerformed(ActionEvent e)
              if (e.getSource()==g.getStart())
                   p.start(s);
                   p.run();
              if (e.getSource()==g.getStop())
                   p.destroy();
                   p.run();
         public static void main(String args[])
              test1 t = new test1();
    class GUI extends JFrame
         JButton start;
         JButton stop;
         public GUI()
              super();
              getContentPane().setLayout(new FlowLayout());
              start=new JButton("start");
              stop=new JButton("stop");
              getContentPane().add(start);
              getContentPane().add(stop);
              setSize(100,100);
         public JButton getStart()
              return start;
         public JButton getStop()
              return stop;
    }

  • Facing the problem in loading the applet in mozilla, Firefox and netscape

    Dear sir,
    Well I am facing the problem regarding loading of applet in firefox,mozilla and netscape. Its working fine in IE6 I have the samplecode which asks for jdk1.4 whenever the applet gets loaded in IE6 and also it works fine for every browser but he is asking jre for every time whenever the page gets loaded even if the jre is installed. I need a code such that it should ask only if the jre is not installed. One more thing is it so that for mozilla or netscape the jre installation files are different.
    pls give the solution.
    Well I am also facing the problem like when I load login page of my applicatoin in netscape or firefox
    I provided the buton on login page on which the hyperlink is present, the hyperlink is of servlet path when I click on the same it shows me the blank page instead he should forward the page to the next jsp webpage where I am showing the applet. But it works fine in IE versions and opera but not in the others.
    Awating for your reply.
    Rgs
    sumeet.

    Issue resolved with the help of ABAP.
    Regards
    Bijudas

  • Best way to close a Runtime.exec() process and how to handle closing it?

    I have multiple Runtime.exec() Processes running and am wondering what the best way it is to close them and take care of closing the resources. I see that Process.destroy() seems to be the way to terminate the Process - is finalize() the best way to close anything in that Process?
    Thanks

    I was involved with your other thread, so I think I know what you are trying to do.
    All Dr's answers are correct.
    Now you have a program A written by you that does Runtime.exec() of multiple instances
    of another program B written by you. You want A to somehow tell B to exit.
    You must use some kind of Inter Process Communication. If this is the only interraction
    between the two programs I can suggest two options. If you anticipate more
    interraction, you may want to look at other means (RMI, for instance, which was proposed
    by EJP in the other thread for starting B, is also useful in exchanging info).
    Solution 1:
    Start a thread in B and read stdin. A will write to stdin a command, such as QUIT.
    When B reads it, it does System.exit().
    Solution 2:
    Start a SocketServer in B that accepts connections on a separate thread.
    When A wants B to exit, it connects to it and writes a command such as QUIT.
    When B reads it, it does System.exit().
    You may note that QUIT is not the only command you can send from A to B, in case you will need more.
    Edited by: baftos on Nov 5, 2007 2:15 PM

  • Applet AccessControlExceptions using Netscape and Java plugin

    I get the following AccessControlException when running a simple applet that tries to connect to an RMI object when using Netscape Communicator 4.5 with the Java plugin supplied with JDK1.3
    java.security.AccessControlException: access denied (java.net.SocketPermission 10.195.57.34:1489 connect,resolve)The HTML page contains the following code:
    <embed type=application/x-java-applet;version=1.3
    code=test.AppletTest archive=AppletTest.jar width=800 height=600>
    </embed>I have modified the default policy file C:\jdk1.3\jre\lib\security\java.policy with the following:
    grant {permission java.security.AllPermission;};
    With the above change the applet works when using appletviewer but if I remove this change I get the same AccessControlException as I do with Netscape.
    This suggests that the Java plugin is not using the default policy file. What am I doing wrong / how can I fix it?
    Thanks,
    Neil

    Alon,
    Thanks for the information. The fact that appletviewer and Netscape may be using different security files because of having different java.homes certainly explains the differences I'm experiencing between the two.
    I've now modified C:\Program Files\JavaSoft\JRE\1.3\lib\security\java.policy which now reads as follows:
    grant codeBase "file:${java.home}/lib/ext/*" {
      permission java.security.AllPermission;
    grant {
      permission java.security.AllPermission;
    };but I've not changed C:\Program Files\JavaSoft\JRE\1.3\lib\security\java.security. Unfortunately this still doen't work with Netscape. In your reply you mention changing java.security files - am I making the wrong changes?
    Neil
    Neil

  • Difference between command line and Runtime.exec()

    Hi all.
    I'm coding some lines to call sqlldr program.
    System info:
    OS: Win2k server
    Java platform: JSK 1.4
    DBMS: Oracle 9i
    I've tested sqlldr in command line and it is OK. But when i call Runtime.exec("sqlldr user/pass@servicename control=mycontrol.ctl")
    the ErrorStream show that: Message 2100 not found,No message file for product=RDBMS ,facility=UL...
    So i had to put a String array which contained "ORACLE_HOME" as the second parameter of exec method. But there's another error appear:
    SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
    ORA-12560: TNS:protocol adapter error
    I checked tnsnames.ora and it's OK. I do the command line again and it's still OK. Why did Runtime.exec("...") method get Error.
    Does Someone solve it for me.
    Thanks so much.

    I'm having the similar/same issue.
    I'm trying to run SQLLdr from JAVA.
    From a command line, it works fine.. From within JAVA, I get..
    SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
    ORA-12640: Authentication adapter initialization failed.
    Did you find a solution to your problem?

  • T2K/T5K type of Solaris servers and Runtime.exec

    It is being consistently observed that on T2k/T5k type of Solaris servers (e.g. T5220), the UNIX commands sent from Java using the Runtime class APIs are not being reveived by Solaris. It does not happen always, only occasionally. But when it happens, the java process hang at process.waitFor(). We are using Java1.6.
    I read the Java World article "When Runtime.exec() won't" and the behavior we are seeing is not because of any of the known pitfalls mentioned in the article. Also the warning in the Runtime API that speaks about the limited buffer size is also not applicable in this case because we do see it working sometimes. All of a sudden Runtime.exec gets stuck. We have also observed that the problem is not dependent on the command we pass through the Runtime.exec API. It happens for any trivial command.
    For more information on the issue, when we execute a 'pstack' on the process id, we see the following output most of the time and the 'truss' output shows the java process to be in a sleeping state:
    # pstack 20650
    ff2c52d8 lwp_park (0, 0, 0)
    ff2bf350 cond_wait_queue (24dd90, 24dd78, 0, 0, 0, 0) + 28
    ff2bf770 cond_wait_common (24dd90, 24dd78, 0, 0, 0, 0) + 294
    ff2bf874 cond_wait (24dd90, 24dd78, 0, 0, 0, 0) + 10
    ff2bf8b0 pthread_cond_wait (24dd90, 24dd78, ff2f3700, 0, f337da00, ecf00000) + 8
    eedddacc kernel_delete_session (24dd60, 24dd58, 0, 1, 3, 1c63c) + 114
    eeddd7dc kernel_delete_all_sessions (0, 1, 0, 1c8b4, 0, eedfa000) + 98
    eedd1eb4 cleanup_library (0, 1, 0, eedfa000, 28180, 3) + 3c
    eedd1f1c kernel_fini (0, 1, 0, eedfa000, 28120, eedfa4a4) + 44
    eede89e0 _fini (ff3f40fc, ff3f5a70, 2b3f4, 0, ff3f4910, 821) + 4
    ff3c54b4 call_fini (ff3f40fc, f43518f0, eede89dc, ff3f42f0, ff3f42a8, ff3f4910) + cc
    ff3cfdc0 remove_hdl (f43518f0, f1c4e2bc, 0, 4000, ff300a54, 4821) + ac8
    ff3ca408 dlclose_intn (f4351978, ff3f4910, ff3f40fc, 2a520, ff3ca4bc, 0) + 24
    ff3ca4e8 dlclose (f4351978, 0, f4350b88, 0, 1c00, 1) + 24
    eee33904 pkcs11_slottable_delete (1, f9e2c0, 46ec90, eee46bb0, 0, 1) + 138
    eee2e42c pkcs11_fini (eee46b8c, 1, eee2e074, eee46000, 17c18, eee46b84) + 4c
    ff241f38 postforkchild_handler (1d18, ff2f3700, 1c00, 4, f337da00, ff2f3700) + 30
    ff2b74bc fork (0, 41, 0, f1c4e744, ff2f3700, f337da00) + 144
    fe8a8ee4 Java_java_lang_UNIXProcess_forkAndExec (ffffffff, 0, fee0c0, fe8c4000, 4, 2) + 6d0
    f940bc20 * java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I+-20552
    f940bbc4 * java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I+0
    f94058b8 * java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V+62
    f9405764 * java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;+182
    f9405874 * java/lang/ProcessBuilder.start()Ljava/lang/Process;+112
    f9405874 * java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;+16                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    If you haven't found the answer yet, I found it in another article. Basically, * and other wildcards are expanded by the shell so Runtime.getRuntime()exec("ls /tmp/*") won't work. You need to use the String[ ] form of exec(), i.e. Runtime.getRuntime()exec( new String[ ] {"sh", "-c", "ls /tmp/*"} )
    hope that helps.

  • Runtime.exec() - using cp and files with spaces on unix

    I'm using the Runtime.exec method to copy files in a unix environment. This works fine until there is a file where the name has spaces in it. I've read the article on the pitfalls of using runtime and how it breaks a string on white spaces and this is what is happening. I've also found another topic that was having the same problem, but they were using /usr/bin/dos2unix. I've tried putting quotes around the filename, but it still breaks on the first space. Any suggestions on how to get around this or another way of doing this would be greatly appreciated.
    An example of the os command string is:
    /usr/bin/cp /tmp/file with space.doc /docs
    Thanks!

    Hi!
    Well I dont have any Sun machine right here to try this but in windows It works great.
    Have you tried something like this ?
    import java.io.*;
    public class OSCopy {
        public static void main(String[] args) {
            try {
                String space = " ";
                String copycmd = "E:\\cp.cmd";
                String source = "E:\\File with space.txt";
                String destination = "E:\\tmp";
                String cmd = copycmd + space + "\"" + source + "\"" + space + destination;
                System.out.println("cmd: " + cmd);
                Runtime runtime = Runtime.getRuntime();
                Process copy = runtime.exec( cmd );
                BufferedReader reader = new BufferedReader( new InputStreamReader( copy.getInputStream()) );
                String line = null;
                while( (line = reader.readLine()) != null ) {
                    System.out.println( line );
            catch (Exception e) {
                e.printStackTrace();
    cp.cmd is a simple dos copy command
    copy %1 %2
    */good luck!

  • Runtime.exec(), linux and redirection

    Hi all,
    I need to exec an external command from java under linux, and have both the stderr and stdout of the command redirected to the
    stdout, so that I can capture them and keep them in synch in the java app. I've tried many combination, but I'm unable to make
    this work: only the standard output shows up. Note that I can make this work under windows.
    A java code example and a small C example to simulate the program to be invoked follows. Running the java program should show both the "messsage" and the "error" lines, but it shows only the "message" ones.
    Note that removing the apparently redoundant ">&1" doesn't solve the problem. I got a suggestion to modify the exec invocation into
    String[] cmd = { "/bin/sh", "-c", "./test1 >&1 2>&1" };
      Process p = Runtime.getRuntime().exec(cmd); but that didn't work eiter.
    Can anyone tell me where I'm wrong?
    Roberto
    ======================= class test.java ================================================
    import java.io.*;
    public class test {
      public static void main(String args[]) {
        new test();
      public test() {
        try {
          Process p = Runtime.getRuntime().exec("/bin/sh -c ./test1 >&1 2>&1")
          InputStream inStr = p.getInputStream();
          BufferedReader inBr = new BufferedReader(new InputStreamReader(inStr));
          String line;
          while((line = inBr.readLine()) != null) {
            System.out.println("line = "+line);
          try {
            p.waitFor();
          } catch(InterruptedException ex) {}
          System.out.println("process terminated with code = "+p.exitValue());
          inBr.close();
        }catch(IOException ex) {
          System.out.println("IOException : "+ex.getMessage ());
    }======================= end of class test.java ================================================
    ======================= test1 program ================================================
    #include <stdio.h>
    int main(int argc, char **argv) {
      int i;
      for(i=0; i<100; i++) {
        fprintf(stdout, "message %d\n", i);
        fprintf(stderr, "error %d\n", i);
    }======================= end of test1 program ================================================

    Redirection dosen't work with Runtime.exec(), it really dosen't have sense. Do the foolowing:
    String[] cmd = { "/bin/sh", "-c", "./test1" };
    Process p = Runtime.getRuntime().exec(cmd);
    OutputStream out = p.getOutputStream();
    //now wrte out to the file, formating as you want
    What is doene obove is execute your command, without redirection, and the obtaininh the output stream of the created process. This is "the place" where the process will write everithig it'll would write in the console if executed there.
    The handle the OutputStream as any other OutputStream, and write it to the HD or do whtever you want.
    Abraham.

  • Reading InputStream from Runtime.exec() and ffmpeg?

    I've got a lot of things going on here and I'm having trouble debugging. I'm working on a streaming music player, and the platform only handles MP3 natively. Specifically, the method that handles incoming requests has to return an InputStream for further processing upstream (out of my visibility).
    I'm trying to extend the music player to play AAC files with the extension ".m4a". To do this, my plan is to transcode from MP3 to AAC using Runtime.exec() and ffmpeg, and then return an InputStream that contains the MP3. This works fine if I use ffmpeg to transcode to a temp file, and then return a FileInputStream constructed from that temp file. But like I said, this is supposed to be a steaming music player, and the blocking for the ~30 seconds it takes to completely transcode to a file is too much of a delay.
    So what I'm trying to do is have ffmpeg transcode to stdout, and then use Process.getInputStream() to return the InputStream that contains ffmpeg's stdout while the transcoding is still going on. This doesn't work and I'm not sure why. (I'm fairly new to java, and this is the first time I've used Runtime.) My player just hangs there. I know Runtime is picky about exhausting the stdout and stderr streams, so I'm not sure if it's something related to that, or if I somehow need to buffer the stdout before returning it, or if I need to run something in a different thread, or if I'm just completely barking up the wrong tree.
    If anyone has any experience with something like this, or can point me at some code that implements something similar, I'd appreciate the help.
    Below a sample of the code in question. Also, for what it's worth, all of the console messages that I put in there are printing, but the music doesn't play.
       public InputStream getStream(String uri) throws IOException
                 System.out.println("Entering Factory.getStream()");
                  System.out.flush();
                File file = new File(URLDecoder.decode(uri, "UTF-8"));
                if (file.exists())
                     if(file.getPath().toLowerCase().endsWith(".mp3")) {
                            // This code for playing MP3 files works correctly
                          System.out.println("Playing MP3");
                          System.out.flush();
                          InputStream in = new FileInputStream(file);
                          return in;
                     else if(file.getPath().toLowerCase().endsWith(".m4a")){
                          System.out.println("Playing M4A");
                          System.out.flush();
                          // Create array for ffmpeg command line
                            // This command line transcodes to STDOUT
                          String[] command = { this.ffmpeg_path,
                                                             "-i", 
                                                             "input.m4a",
                                                             "-acodec",
                                                             "libmp3lame",
                                                             "-ac",
                                                             "2",
                                                             "-ab",
                                                             "256",
                                                             "-f",
                                                             "mp3",
                          // Begin transcoding with ffmpeg
                          System.out.println("Transcoding...");
                          System.out.flush();
                          Runtime runtime = Runtime.getRuntime();
                          Process ffmpeg = runtime.exec(command);
                          // Must exhaust error stream, or the application can become deadlocked.
                          System.out.println("Exhausting stderr...");
                          System.out.flush();
                          this.exhaustInputStream(ffmpeg.getErrorStream());
                          // Return ffmpeg's stdout as an input stream
                          System.out.println("Returning stdout...");
                          System.out.flush();
                          return ffmpeg.getInputStream();
                     else {
                          System.out.println("Unsupported Audio File");
                          System.out.flush();
                          return null;
                else
                    // We aren't requesting a file, so let the API handle the request upstream...
                    return super.getStream(uri);
         private void exhaustInputStream(final InputStream inputStream) {
                  // Since InputStream.read() blocks, exhast the stream in a separate thread
                  new Thread() {
                       public void run() {
                            try {
                                 while(inputStream.read() >= 0) {
                                      // Just throw the bytes away
                            catch(IOException e) {
                                 e.printStackTrace();
                  }.start();
             }

    Read this article
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Maybe you are looking for

  • View content of multiple smart albums in Aperture 3

    I'm having difficulty accomplishing the following in Aperture 3.1.3 in Lion: I'd like to filter content from a folder (of several projects) that includes: One star or greater AND (orientation IS portrait OR aspect ratio IS 16:9). I'd like to view thi

  • How can I load pics from camera without spaces in the filename (PSE5)

    Hello, I want to load the pics from my Fuji Camera with my newly acquired Photoshop Elements 5 into its database as simple as possible. I get offered several ways of renaming the pics during the import. Unfortunately the date formats offered (for fol

  • How to allow user upload file on applet??

    Sorry I'm new to programming here, but I'm trying to allow user to upload a file to the server so the program inside the server can user the file as input. I've noticed that JFileChooser, the ideal class for this, is not allowed on the applet, so I d

  • Can AppleWorks from my '05 G5 be installed in my new iMac?

    When I purchased my g5 in 2005, appleworks came standard. yesterday, I purchased a new iMac and now appleworks (along with spreadsheet and something else i'll never use) cost $70 or $80, so I was hoping that I may be able to install the appleworks fr

  • Rejected password with RoadRunner (RR)

    Over the past few months, I've had an increasing number of password rejections from my RoadRunner internet provider using Apple Mail. Frustration is growing. My password is being entered correctly, but it immediately throws up a dialog box saying "Th