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

Similar Messages

  • Displaying input from Runtime.exec()

    Hi there, after all my troubles, I'm finaly able to get all the input from the unix machine using Runtime.exec() and to have it come out pretty quick. My new problem now is that I need to take that input and display it onto a textPane. Anyone who can help me do that? here is the code I have written, along with the method I use called setPaneText():
    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 (Exception ioe)
    ioe.printStackTrace();
    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    Object source = evt.getSource();
    String serverComm;
    serverComm = "";
    serverComm = pp.getServerComm();
    if(source == jMenuItem13)
    try
    String osName = System.getProperty("os.name");
    Runtime rt = Runtime.getRuntime();
    Process commandReturn = rt.exec(serverComm + " /usr/local/bin/dlgexec pd_rm_cm trashcan");
    //StreamGobbler errorGobbler = new
    //StreamGobbler(commandReturn.getErrorStream(), "ERROR");
    StreamGobbler outputGobbler = new
    StreamGobbler(commandReturn.getInputStream(), "OUTPUT");
    //errorGobbler.start();
    outputGobbler.start();
    int exitVal = commandReturn.waitFor();
    System.out.println("exitVal = " + exitVal);
    if(exitVal == 0)
    System.out.println("inside the trashcan if");
    int cnt = 0;
    String outText []= new String [10000];
    BufferedReader buffy = new BufferedReader(new InputStreamReader(outputGobbler.is));
    while((outText[cnt]=buffy.readLine()) != null)
    cnt++;
    if(cnt == 9000)
    break;
    TextAreaPanel tp;
    tp = new TextAreaPanel();
    for(int cnt2 = 0; cnt2 < cnt; cnt2++)
    String temp;
    temp = outText[cnt2] + "\n";
    tp.setPaneText(temp);
    jPanel1.removeAll();
    jPanel1.add(tp, BorderLayout.CENTER);
    jPanel1.validate();
    this.repaint();
    catch(Throwable t)
    t.printStackTrace();
    and here is the method that I call
    public void setPaneText(String message)
    jTextArea1.setEnabled(true);
    //jTextArea1.setEditable(false);
    String outText = message;
    jTextArea1.setText(message);
    jScrollPane1.setViewportView(jTextArea1);
    //return outText;
    String message;

    @Op. Please learn how to use code formatting when you post code:
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Runtime.exec() and subprocesses

    I am running a bat file through Runtime.exec(). Conetent of bat file look
    likes following
    E:\Progra~1\Brio\SQRServer\ORA\BINW\sqrw d:/brio/par/par_pqa.sqr
    ibprod/active1@pscore -oC:/TEMP/sqr.log -printer:pd 88
    d:/Brio_Reports/report1.pdf d:/brio/
    exit
    Now this batch file starts another executable program. That program creates
    a report in a particular directory and exit the process. When I run this
    file from command prompt it runs fine. But if I try same thing from
    Runtime.exec(), my program hangs.
    From windows process monitor tools it seems that it start a new process but
    that process never ends. If I end that process forcefully then pointer
    again returns to my java program.
    any idea how to solve this problem.

    Is there maybe any stdout or stderr (console so to say) output which is not taken care of when the thing is called from Java?

  • Runtime.exec and setting environment variables

    Runtime.exec and setting environment variables
    I need a decent example which works on Windows.
    Got any?

    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() and apostrophe?

    Hi there,
    I try to execute a Unix program using Runtime.exec(). This works as long as I don't need any apostrophe characters:
    works: <path>/<program> <someArguments>doesn't work: <path>/<program> <someArguments> -ls='rm /tmp/test.xml'In the latter case, I get an error message stating a syntax error.
    But when I enter exactly the same command directly into the shell, I don't get an error. Instead, the desired behavior occurs.
    Note: The parameter "-ls" lets the program execute a command once certain criteria are met. But the command in question is not part of the problem. For example, -ls=ll works...
    Thanks in advance for your help! :-)
    btw.: I've already read the "When Runtime.exec() won't" document, so I'm quite sure I didn't run into the shown pitfalls. Well, it could be related to the "Runtime.exec() is not a command line" section, but I haven't been able to figure out how to correct it.
    Kind regards,
    Dennis

    I guess you can remove the test for the SunOS operating system
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.lang.Runtime;
    import java.lang.Process;
    import java.lang.InterruptedException;
    import java.util.StringTokenizer;
    public class JExec {
         private static int lastExitValue = 0;
         public static int getLastExitValue() {
              return lastExitValue;
        public static final String osName= System.getProperty("os.name");
        public static byte[] execUNIXcmd(String commande, byte[] outputData, boolean closeStream) throws NullPointerException {
              Runtime runtime = Runtime.getRuntime();
              Process process = null;
              InputStream inputStream = null;
              OutputStream outputStream = null;
              byte[] bBuf = null;
              String tmpStr = null;
              if (!osName.equals("SunOS")) {
                   System.err.println("Unsupported Operating System");
                   throw new NullPointerException();
              } else {
                   // Dans le cas de SunOs
                   try {
                        process = runtime.exec(commande);
                        outputStream = process.getOutputStream();
                        inputStream = process.getInputStream();
                        if (outputData != null) {
                             outputStream.write(outputData);
                        if (closeStream) outputStream.close();
                        process.waitFor();
                        lastExitValue = process.exitValue();
                        bBuf = new byte[inputStream.available()];
                        inputStream.read(bBuf, 0, inputStream.available());
                        if (!closeStream) outputStream.close();
                        inputStream.close();
                        return bBuf;
                   } catch (InterruptedException e) {
                        System.err.println("ERROR ("+osName+"): Enable to wait the process");
                        throw new NullPointerException();
                   } catch (IOException e) {
                        System.err.println("ERROR ("+osName+"): Enable to read input lines");
                        System.err.println("->"+e.getMessage());
                        throw new NullPointerException();
         public static void main (String[] s) {
              String commande = "echo '$PATH'";
              System.out.println(new String(JExec.execUNIXcmd("sh -e", commande.getBytes(), true)));
    }

  • Runtime Exec and ProcessBuilder

    I have an object (textTicket) which is a formatted transaction label. Here is an example:
    CROSS PLAINS QUARRY CROSS PLAINS TN 37049 2549
    MATL SPREADING NOT GUARANTEED
    615-654-9942 TOLL FREE 877-654-9942
    Date: 01/19/2009 04:45:46
    Job No: PU-2008
    Q Num::
    Cust No: 30000001 Src Num::
    Sold To: CASH SALE
    Address: INTERNAL
    NASHVILLE,TN 37202
    Ord By:
    Ord No: Rate Zone:
    Location:THANKS YOU
    Mat. & Haul170.28 Sev Tax:0 Tax16.60
    Acc Total:1308.16
    Total186.88
    3/4 TO 4/67'S
    Gross: 40500 St. Item:
    Tare: 12120 P.O.: MIKE MILLER
    Net: 28380.0
    Net Tons: 14.19
    Proj:
    Truck #: 1
    Hauler: Phy Truck: 248251
    I am attempting to pass this textTicket object to a shell script that will send it out the port for printing. I have tried using the Java Comm API however, we have intermittent problems with the API running on an Oracle Appserver. Sometimes, the data never gets sent to the port. So what I am trying to do is just call a shell script that echos the textTicket out the port via redirection. The problem arise when I use the ProcessBuilder or runtime exec and I have to convert the textTicket to a string via textTicket.toString. The textTicket then losing all of its formatting. Any ideas on how to keep the formatting as I am passing the textTicket to the shell script.

    My example did not save into the post very well. For instance, the first line "Cross Plains Quarry" should be center on the paper. The object contains \t\t to get it center.
    For example on the runtime.exec, I am doing the following
    public void printShell(String port, String string){
         String[] params={"/usr/ts/bin/prttick.sh", string, port};
         try {
                   Process p=Runtime.getRuntime().exec(params);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   SerialCommunicator.logger.debug("error" + e.getMessage());
    The variable string is textTicket.toString();

  • Who worked with ICS' Model 4896 GPIB? I can not count the data from the module. Can prompt as it to make. It is desirable with examples (data read-out from the module and data transmission between channels. It is in advance grateful.

    I can not count the data from the module. Can prompt as it to make. It is desirable with examples (data read-out from the module and data transmission between channels. It is in advance grateful.

    Hello. Most of the engineers in developer exchange are more familiar
    with NI products. Contacting ICS for technical support is a better
    course of action.

  • Reading data From XML file and setting into ViewObject to Pouplate ADF UI

    Hi,
    I have following requirement.
    I would like to read data from XML file and populate the data in ViewObject so that the data can be displayed in the ADF UI.
    Also when user modifies the data in the ADF UI, it should be modified back into to ViewObject.
    Here is an example - XML file contains Book Title and Author. I would like to read Book Title and Author from XML file and set it into ViewObject Attribute and then display Book title and Author in ADF UI page. Also when user modifies Book title and Author, I would like to store it back in View Object.
    Please help me with this requirement and let me know if any solution exist in ADF, for populating the ADF UI screen fields with external XML file data.
    Thanks

    Read chapter 42 http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm of the fusion developer guide
    Section 42.7, "Reading and Writing XML"
    Section 42.8, "Using Programmatic View Objects for Alternative Data Sources"
    Timo

  • We want to read data from weigh bridge and display in oracle forms & store

    Sir/Madam,
    in our organisation we had one requirement. i.e is reading data from weigh bridge using serial port, displying that data in oracle forms and when ever user click save button we store that into my oracle database. we are using oracle 8i and forms 6i and windows OS environment. we don't know reading data from serial port and placing that into form items. please help me as early as possible if there is any property available in d2k regarding this requirement .
    thank you,
    vishnu

    There's no property in Forms that makes you read serial ports, but as far as I know you need to know the API of the machine which you want to read data from (it should come with machine's manual) and then it will be easy to store it in forms item.
    Tony

  • How do I read text from specific rows and columns in a tree structure?

    How do I read text from specific rows and columns in a tree structure? In a table you can specify the cell to read from but I have not been able to figure out how to do this with a tree structure.

    You need to set two properties to activate the correct cell and then you can read it's string property.
    The positioning properties are the "ActiveItemTag" and
    "ActiveColNum" properties. With them you select the tree item by it's tag and the active column. The string can then be read from the "Cell String" property.
    MTO

  • Reading Data from Unix file and write into an Internal table

    Dear all,
                     I am having an requirement of reading data from unix file and write the same into an internal table..how to do that ...experts please help me in this regard.

    Hi,
    do like this
    PARAMETERS: p_unix LIKE rlgrap-filename OBLIGATORY.
    DATA: v_buffer(2047) TYPE c.
    DATA: BEGIN OF i_buffer OCCURS 0,
            line(2047) TYPE c,
    END OF i_buffer.
    * Open the unix file..
    OPEN DATASET p_unix FOR INPUT IN TEXT MODE.
    <b>IF sy-subrc NE 0.
    *** Error Message "Unable to open file.
    ELSE.</b>
       DO.
         CLEAR: v_buffer.
         READ DATASET p_unix INTO v_buffer.
         IF sy-subrc NE 0.
            EXIT.
         ENDIF.
         MOVE v_buffer TO i_buffer.
         APPEND i_buffer.
      ENDDO.
    ENDIF.
    CLOSE DATASET p_unix.
    <b>Reward points if it helps,</b>
    Satish

  • Execute java class from a batch file called from runtime.exec

    Hi.
    I don´t know if this question fits here.
    I wan´t to execute a batch file (on Win XP) with runtime.exec. That batch file will execute another java program.
    I have the following code:
    Resolutor.java
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class Resolutor {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Runtime r = Runtime.getRuntime();
              //String[] command = { "cmd.exe", "/C",".\\lanzar.bat .\\ .\\ 001.res:001.dtt" };
              String[] command = { "cmd.exe", "/C",".\\tarea\\lanzar.bat " + args[0] + " " + args[1] + " " + args[2]};
              try {
                   //Process proceso = Runtime.getRuntime().exec("lanzar.bat");
                   Process proceso = Runtime.getRuntime().exec(command);
                   InputStream stderr = proceso.getErrorStream();
                InputStreamReader isr = new InputStreamReader(stderr);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                System.out.println("<ERROR>");
                while ( (line = br.readLine()) != null)
                    System.out.println(line);
                System.out.println("</ERROR>");
                   int exitVal = proceso.waitFor();
                   System.out.println("EXITVAL: " + exitVal);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }lanzar.bat
    java Lanzador %1 %2 %3Lanzador.java
    import java.util.Vector;
    public class Lanzador {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Repetitiva rpt=new Repetitiva();
              String rutaFicheros=args[0];
              String rutaResultado=args[1];
              String[] ficheros=args[2].split(":");
              Vector<String> ficheroDatos=new Vector<String>();
              for(int i=0;i<ficheros.length;i++){
                   ficheroDatos.add(ficheros);
                   System.out.println(ficheros[i]);
              System.out.println("RUTA DE FICHEROS: " + rutaFicheros);
              System.out.println("RUTA DE RESULTADOS: " + rutaResultado);
              System.out.println("CALCULAR");
              rpt.setRepetitiva(ficheroDatos, rutaFicheros, rutaResultado);
              rpt.calcular();
    }I´ve got Resolutor.class in /res and the other two files (and the rest of the files for running) in /res/tarea.
    If I execute /res/tarea/lanzar.bat from the command line everything works fine, it calls java and runs lanzador without problem.
    The problem comes when I try to execute the batch file via Resolutor.class. It executes the batch file without problem, but it throws a *java.lang.NoClassDefFoundError: Lanzador* when launching the new java application.
    Any ideas of how can I solve that problem. (It must do it via batch file).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Well, I tried putting in the bat file java -classpath .\tarea Lanzador %1 %2 %3 and didn´t work.
    I ve tried the bat modification, and the directory in x.txt is k:\res instead of k:\res\tarea.
    I´ve tried to modifiy it to java .\tarea\Lanzador and didn´t work so I have put a cd like the following and it appears to work.
    cd tarea
    java Lanzador %1 %2 %3Thanks for the replies.

  • Read data from Excel file and diaplay in Webdynpro

    Hi all,
    I need some help. I have a Excel file with set of  name, phonenumbers . I want to know how to display the data using Webdynpro. Could some one help me. help is appreciated and I promise to award points for right answer.
    Thank you
    Maruti

    <b>Hi
    i can explain you to read data from Excel file
    First You have to download the jxl.jar file. You can get this file from the Below site
    </b><a href="http://www.andykhan.com/jexcelapi/download.html">jexcelapi jar</a>
    It will be in Compressed Fromat So Unzip it to get the Contents
    After Unzipping The File You will get a Folder (jexcelapi/jxl.jar)
    Now in NWDS open web dynpro explorer, Right Click Your Project, a popup menu will appear and in that click Properties
    You will get window displaying your Project Properties
    On Left Side of the window You Will Find "Java Build Path"
    Click That "Java Build Path" and you will get 4 Tabs Showing ( Source,Projects,Libraries,Order and Export)
    Click Libraries Tab
    You will find options many options buttons
    In that click the Button "Add External Jars"
    You will get Window in order to fecth the jxl.jar file from the location you had stored
    After selecting the jxl.jar i will get displayed and click ok
    Now Open Navigator
    Open Your Project
    You will find Lib folder
    Copy the jxl.jar to that lib folder
    Note : You cannot Read the Content from the excel file directly
    First You Have to copy that file to the Server,
    And from the Server you can get the file absolute path
    With the absolute path you can read the contents of the Excel file
    You have to save the Excel file as .xls Format and Not as xlsx format i will not accept that...
    You have Upload the Excel file from the Server Using the File Upload UI Element
    This Coding will extract 3 columns from the Xls File
    Coding
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    import com.sap.fileupload.wdp.IPrivateFileUpload_View;
    import com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource;
    public void onActionUpload_File(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionUpload_File(ServerEvent)
        IPrivateFileUpload_View.IContextElement element1 = wdContext.currentContextElement();
        IWDResource resource = element1.getFileResource();
        element1.setFileName(resource.getResourceName());
        element1.setFileExtension(resource.getResourceType().getFileExtension());
        //@@end
    public void onActionUpload_File_in_Server(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionUpload_File_in_Server(ServerEvent)
        InputStream text=null;
        int temp=0;
        try
             File file = new File(wdContext.currentContextElement().getFileResource().getResourceName().toString());
             FileOutputStream op = new FileOutputStream(file);
             if(wdContext.currentContextElement().getFileResource()!=null)
                  text=wdContext.currentContextElement().getFileResource().read(false);
                  while((temp=text.read())!=-1)
                       op.write(temp);                                      
             op.flush();
             op.close();
             path = file.getAbsolutePath();
             wdComponentAPI.getMessageManager().reportSuccess(path);
        catch(Exception e)
             e.printStackTrace();
        //@@end
    public void onActionUpload_Data_into_Table(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionUpload_Data_into_Table(ServerEvent)
        try
              Workbook wb =Workbook.getWorkbook(new File(path));
              Sheet sh = wb.getSheet(0);
              //wdComponentAPI.getMessageManager().reportSuccess("Columns = "+sh.getColumns());
              //wdComponentAPI.getMessageManager().reportSuccess("Rows = "+sh.getRows());
              int columns = sh.getColumns();
              int rows = sh.getRows();
              int i=0;
             for(int j=1;j<=rows;j++)
                       ele=wdContext.nodeTable_Data().createTable_DataElement();
                       Cell c1 = sh.getCell(i,j);
                      ele.setTab_Name(c1.getContents());
                       Cell c2 = sh.getCell(i+1,j);
                       ele.setTab_Degree(c2.getContents());
                          Cell c3 = sh.getCell(i+2,j);
                       ele.setTab_Percentage(c3.getContents());
                       wdContext.nodeTable_Data().addElement(ele);
        catch(Exception ex)
             wdComponentAPI.getMessageManager().reportSuccess(ex.toString());
        //@@end
       * The following code section can be used for any Java code that is
       * not to be visible to other controllers/views or that contains constructs
       * currently not supported directly by Web Dynpro (such as inner classes or
       * member variables etc.). </p>
       * Note: The content of this section is in no way managed/controlled
       * by the Web Dynpro Designtime or the Web Dynpro Runtime.
      //@@begin others
      String path;
      IPrivateFileUpload_View.ITable_DataElement ele;
    //@@end
    Regards
    Chandran S

  • Running ftp from runtime exec()

    How would I run ftp from exec()? Can I run a script that is ftping from exec()? Why would anyone go through the trouble of writing their own ftp code, if you can just call a script from the exec() method? I am going to be running ftp from a servlet to send a file to a mainframe, where it will run and create an xml file that the servlet will then post to the screen. should I be using java's ftp commands, or will my script way work fine?
    Thanks

    How would I run ftp from exec()?Like any other program. It would be good to read the article http://www.javaworld.com/jw-12-2000/jw-1229-traps.html first to get it right the first time.
    Can I run a script that is ftping from exec()?I don't see any objections.
    Why would anyone go
    through the trouble of writing their own ftp code, if
    you can just call a script from the exec() method?Good question. 1) you are making your application platform dependent by using a platform depenent program 2) Runtime.exec() can't be used in applets but ftp over a socket connection is possible 3) There are already good packages for it (eg. at www.fooware.com) written for it so you don't need to write anything yourself (and 4: just because it's fun!)
    I am going to be running ftp from a servlet to send a
    file to a mainframe, where it will run and create an
    xml file that the servlet will then post to the
    screen. should I be using java's ftp commands, or
    will my script way work fine?
    If you have a working script and you know you will work on only one platform calling a script with exec will be just fine.

  • Rsync from Runtime.exec

    I'm trying to run following command with Runtime.exec:
    rsync -auz sourceHost:'path1 path2' tmpSo I have following code to run this command:
    command[0] = "rsync";
    command[1] = "-auz";
    command[2] = "sourceHost:'path1 path2'";
    command[3] = "tmp";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    InputStream stdin = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) {
          System.out.println(line);
    stdin = proc.getInputStream();
    isr = new InputStreamReader(stdin);
    br = new BufferedReader(isr);
    line = null;
    while ( (line = br.readLine()) != null) {
          System.out.println(line);
    int exitVal;
    try {
          exitVal = proc.waitFor();
    } catch (InterruptedException e) {
          throw new IOException(e.getMessage());
    if (exitVal != 0) {
          throw new IOException("Exit value was " + exitVal + " that means an error occured" +
              " during rsync call");
    }What happens is that when I run the code rsync gives me following error:
    rsync: link_stat "path1 path2" failed: No such file or directory (2)
    rsync error: some files could not be transferred (code 23) at main.c(812)
    client: nothing to do: perhaps you need to specify some filenames or the --recursive option?
    java.io.IOException: Exit value was 23 that means an error occured during rsync call
            at RSyncTest.rsyncBinaryData(RSyncTest.java:156)
            at RSyncTest.main(RSyncTest.java:80)Can anyone think of what's wrong here?
    Regards and Thanks,
    David

    In Java version 1.3 (and later) method exec() of class Runtime returns a Process instance when invoked. The process object returned is what you need to manage.

Maybe you are looking for