How to call other program in java

how do i write code to call a program, software in window envirenment?
such as opening Microsoft Excel files using Microsoft excel?
plz help

public static void main(String[] args)
         try
                 Runtime.getRuntime().exec("Book1.xls");
         catch (IOException ed)
}i tried, but it not working , plz help

Similar Messages

  • Help! how to run other programs using java

    how can i run other programs or exe files using java, anyone can give sample codes for this.
    ex. if I click [run MsWord] button, then msWord automatically lunch

    RunTime.getRuntime().exec(string command)
    I guess, it might help you..java.lang.Runtime

  • Call other programs from Java

    There is this command line program I want to wrap with a Java class in order to make it available so that it can be transparently called.
    How can I call or execute external programs/commands from JAVA...
    is not native code that I want to run...
    Thank you

    Runtime.getRuntime().exec("your command line")... you could read more about it in the API documentation.

  • How to call other execs from java application

    What is the best way to make a call to execute an external executable written in another language (i.e. c++ or ada95) from within a java application?

    Hi,
    Runtime.getRuntime().exec(new String[]{"C:\\Office\\winword.exe"});
    you should catch IOException as well.
    Phil

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • Programming to call other programs

    I am in need of direction as I am unable to find any help on my current problem. I am developing a program that will create a database of triples from an xml document. My use of existing programs such as 4suite's '4rdf' which is called by the command prompt has left me with the issue of how do you program in java, to call other programs and/or the command line. I need to pass in arguments and execute the program from within one java program. Is this possible? Help is urgently required. Please help. Cheers Dave.

    Allways happy to assist my follow programmers, this is a class I developed (with help from online documents of course) to contain all my executing needs. Note that you need to place these two classes in a package yourself, they are part of quite a complex one where I use them.
    public class Semaphore {
      protected boolean blocked;
      public Semaphore() { blocked = false; }
      public synchronized void waitUntilSignalled() {
           if(blocked == false){
             try {
                    blocked = true;
                    wait();
                } catch(  InterruptedException e ) { }
      public synchronized void setSignalled() {
        if (blocked == true){
              blocked = false;
              notifyAll();
         public static class ExecStreamThread extends Thread
             InputStream is;
             OutputStream os;
             Semaphore sem;
             public ExecStreamThread(InputStream is, OutputStream redirect)
                 this.is = is;
                 this.os = redirect;
                 sem = null;
             public ExecStreamThread(InputStream is, OutputStream redirect, Semaphore theSem)
                 this.is = is;
                 this.os = redirect;
                 sem = theSem;
             public void run()
                  try
                       PrintWriter pw = pw = new PrintWriter(os);
                       InputStreamReader isr = new InputStreamReader(is);
                       BufferedReader br = new BufferedReader(isr);
                       String line=null;
                       while ( (line = br.readLine()) != null)
                                pw.println(line);
                           pw.flush();
                  } catch (IOException ioe){
                      // don't have to do anything, the parent thread will have found out the process errored
                  // run is complete, signal the semaphore
                  if(sem != null){
                       sem.setSignalled();
         public static final int OSTYPE_WINDOWS = 1;
         public static final int OSTYPE_WINNT = 2;
         public static final int OSTYPE_WINCE = 3;
         public static final int OSTYPE_LINUX = 4;
         public static final int OSTYPE_MAC = 5;
         public static final int OSTYPE_SOLARIS = 6;
         public static final int OSTYPE_NETWARE = 7;
         public static final int OSTYPE_OS2 = 8;
         public static final int OSTYPE_UNKNOWN = 9;
         private static int type = OSTYPE_UNKNOWN;
         private ExecUtil()
              @return an integer identifying the OS (one of the OSTYPE constants)
         public static int getOs()
              if(type == OSTYPE_UNKNOWN){
                   String osname = System.getProperty("os.name").toLowerCase();
                   if(osname.indexOf("windows") != -1){
                        if(osname.indexOf("nt") != -1 || osname.indexOf("2000") != -1 || osname.indexOf("xp") != -1){
                             type = OSTYPE_WINNT;
                        } else if(osname.indexOf("ce") != -1){
                             type = OSTYPE_WINCE;
                        } else {
                             type = OSTYPE_WINDOWS;
                   } else if(osname.indexOf("linux") != -1 || osname.indexOf("bsd") != -1){
                        type = OSTYPE_LINUX;     
                   } else if(osname.indexOf("mac os") != -1 || osname.indexOf("macos") != -1){
                        type = OSTYPE_MAC;
                   } else if(osname.indexOf("solaris") != -1){
                        type = OSTYPE_SOLARIS;     // could also be old freebsd version
                   } else if(osname.indexOf("netware") != -1){
                        type = OSTYPE_NETWARE;
                   } else if(osname.indexOf("os/2") != -1){
                        type = OSTYPE_OS2;
                   } else {
                        type = OSTYPE_UNKNOWN;     
              return type;
              @return the prefix to execute a shell command. For example "command /c " to execute a shell command on windows9X machines.
         public static String getShellString()
                 String appendStr = "";
                 int ostype = getOs();
                 if(ostype == OSTYPE_WINDOWS){
                      appendStr = "command /c ";
                 } else if(ostype == OSTYPE_WINNT || ostype == OSTYPE_WINCE){
                      appendStr = "cmd /c ";     
                 } else if(ostype == OSTYPE_LINUX || ostype == OSTYPE_MAC){
                      appendStr = "/bin/sh -c ";     
                 } // add other shell executers
                 return appendStr;
         /** execute a command and ignore any output it generates (output is sent to System.out and System.err).
              It is valid to pass a command containing multiple parameters
              @param command the command to execute
              @return the exit code the process generated
         public static int exec(String command)
              throws IOException
              return exec(command, false, System.out, System.err);
         /** execute a (shell) command and ignore any output it generates (output is sent to System.out and System.err).
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand)
              throws IOException
              return exec(command, shellCommand, System.out, System.err);
         /** execute a (shell) command and catch the output it generates.
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand, OutputStream output)
              throws IOException
              return exec(command, shellCommand, output, System.err);
         /** execute a command and catch the output it generates.
              It is valid to pass a command containing multiple parameters.
              @param command the command to execute
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, OutputStream output)
              throws IOException
              return exec(command, false, output, System.err);
         /** execute a command and catch the output (stdout) and errors (stderr) it generates.
              It is valid to pass a command containing multiple parameters.
              @param command the command to execute
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @param error the output stream to send the error output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, OutputStream output, OutputStream error)
              throws IOException
              return exec(command, false, output, error);
         /** execute a command and catch the output (stdout) and errors (stderr) it generates.
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @param error the output stream to send the error output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand, OutputStream output, OutputStream error)
              throws IOException
             if(shellCommand == true){
                  String appendStr = getShellString();
                  command = appendStr + command;
             String[] realcommand;
             if(command.indexOf(" ") != -1){
                  realcommand = command.split(" ");
             } else {
                  realcommand = new String[1];
                  realcommand[0] = command;     
             try{
                  Process ls_proc = Runtime.getRuntime().exec(realcommand);
                   ExecStreamThread execOutput;
                   ExecStreamThread execError;
                   execOutput = new ExecStreamThread(ls_proc.getInputStream(), output);
                   execOutput.start();
                   execError = new ExecStreamThread(ls_proc.getErrorStream(), error);
                   execError.start();
                 int exitvalue = ls_proc.waitFor();     
                   if(output != null) { output.flush(); }
                   if(error != null) { error.flush(); }
                   return exitvalue;
              } catch(Exception e){
                   throw new IOException(e.getMessage());
         public static void main(String[] args)
              try{
                   int code = ExecUtil.exec("javac test.java", System.out, System.err);
                   System.out.println("Exit code was : " + code);
                   code = ExecUtil.exec("java test", System.out, System.err);
                   System.out.println("Exit code was : " + code);
              } catch(IOException e){
                   System.out.println("failed due to exception: " + e);
              try{
                   int code = ExecUtil.exec("dir/w", true, System.out, System.err);
                   System.out.println("Exit code was : " + code);
              } catch(IOException e){
                   System.out.println("failed due to exception: " + e);
    }

  • How to call gnuplot command from java

    Hi there,
    In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
    By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
    Thanks a lot for any suggestions!
    Jack

    Hi, there:
    Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
    BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
    Thanks,
    Jack
    P.S. Would you guys answer my question after I use up my duke dollars? :- )

  • How to call one program from another program

    Hai,
      How to call one program through another program.
    Example.
       I have two programs 1.ZPROG1 2. ZPROG2.
    When i execute ZPROG1 at that time it should call ZPROG2.

    Hi ,
    u can use submit statement to call a program .
    DATA: text       TYPE c LENGTH 10,
          rspar_tab  TYPE TABLE OF rsparams,
          rspar_line LIKE LINE OF rspar_tab,
          range_tab  LIKE RANGE OF text,
          range_line LIKE LINE OF range_tab.
    rspar_line-selname = 'SELCRIT1'.
    rspar_line-kind    = 'S'.
    rspar_line-sign    = 'I'.
    rspar_line-option  = 'EQ'.
    rspar_line-low     = 'ABAP'.
    APPEND rspar_line TO rspar_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'H'.
    APPEND range_line TO range_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'K'.
    APPEND range_line TO range_tab.
    SUBMIT report1 USING SELECTION-SCREEN '1100'
                   WITH SELECTION-TABLE rspar_tab
                   WITH selcrit2 BETWEEN 'H' AND 'K'
                   WITH selcrit2 IN range_tab
                   AND RETURN.
    regards,
    Santosh thorat

  • How to call driver program internal table in a form

    how to call driver program internal table in a form? Given below is my code
    TABLES: VBRK,VBAK,ADRC,KNA1,VBRP,VBAP,J_1IMOCOMP.
    DATA: BEGIN OF IT_CUST_ADD OCCURS 0,
    STREET LIKE ADRC-STREET,
    NAME LIKE ADRC-NAME1,
    POST_CODE LIKE ADRC-PSTCD1,
    CITY LIKE ADRC-CITY1,
    CUST_TIN LIKE KNA1-STCD1,
    END OF IT_CUST_ADD.
    DATA: BEGIN OF IT_IN_DA OCCURS 0,
    VBELN LIKE VBRK-VBELN,
    FKDAT LIKE VBRK-FKDAT,
    END OF IT_IN_DA.
    now suppose these are my internal table. what should i write in FORM INTERFACE (associated type)

    Hi Sashi, this will solve ur problem.
    Check the below link.
    REG:PEFORM IN SCRIPT
    kindly reward if found helpful.
    cheers,
    Hema.

  • How To Call HTML Page Through Java Swing Page  ???....

    Hi All ;
    Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
    Regards ;

    Hi,
    you can use HTML fragments on a panel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    However, to integrate a browser you need 3rd party software like IceBrowser
    If you Google for: HTML Swing
    then you find many more hints
    Frank

  • How to call Jakarta Ant via JAVA?

    Hi.
    My application has a new menu. This menu creates a build.xml Ant file.
    Now, when this menu is invoked , its action should call
    Jakarta Ant, after creating the xml file, so that the build.xml will
    do what is necessary.
    How can I do it? That is, how to call the Ant via java?
    Is there any way to use an Ant object?
    Thanks?
    Rodrigo Pimenta Carvalho.

    There is a slight problem in that
    PorjectHelper.configureProject is deprecated, but
    that is what Main calls...maybe someone else will
    complete this thread with an alternative call.The javadoc recommends using the non static method parse() instead. This is available by implementing class ProjectHelperImpl. An alternative to the code above might look like this:
            Project ant = new Project();
            ProjectHelper helper = new ProjectHelperImpl();
            ant.init();
            helper.parse(ant, new File("build.xml"));
            ant.executeTarget("clean");you might also want to add a logger so you can see the output of events generated by ant. The DefaultLogger class would be used like this. Simply add the code before you call the ant.init().
            DefaultLogger log = new DefaultLogger();
            log.setErrorPrintStream(System.err);
            log.setOutputPrintStream(System.out);
            log.setMessageOutputLevel(Project.MSG_INFO);
            ant.addBuildListener(log);

  • How to run native program with Java program?

    Hello
    I've got following problem. I'd like to write file browser which would work for Linux and
    Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
    Cheers

    Try this:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("ls -l");
    InputStream stream = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stream);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) .....
    "if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

  • How to call Other webapplication resource ,which is in different contex.

    How to call Other webapplication resource ,which is in different contex.

    Hi,
    Hope you have a directory or the file path of the file stored in the application server.
    Please check this...
    Step1: Create a RFC function module in SE37 with exporting the file name with full path and importing to the table for storing the records of the file. You can use the open dataset for output statement for reading the data from the application server. Also check transaction CG3Z & CG3Y for uploading and downloading the file from application server.
    Step2: call this RFC enabled FM in your program with destination as target system(file stored) to get the data from the file.
    If you are not sure about the file path, then you the FM which you specified to get the actual and correct file path.
    Thanks!...
    Regards,
    Suresh.D

  • How to call other Entity service

    Hi,
    How to call other Entity service to our entity service?
    Regards
    Ashif

    Hi,
    I mean,  need to call the other project entity service to my project application service, for example, am having the project with the name "aaa", and i wanna to get the entity services of the other project "xxx" to my project "aaa".
    Can you please, let me know how to call the same.
    provide me some links for the same.
    Thanks

  • How to call other number its number did my phone number into blacklist? Please......May I know...

    How to call other number its number did my phone number into blacklist? Please......May I know...

    If someone somehow blacklisted your phone number, you would have to either call them from a number their phone will allow or get them to white list your number.

Maybe you are looking for

  • All quantity base on storage location.... 4 questions...

    hi experts, i want to write a report which can show all the quantitiy base on storage location and i have four questions .... 1 . has somebody can tell me where i can find the confirmed qty ? is it in VBEP-BMENG ? 2 . how to know one material in one

  • Pricing Procedure problem when creating order w/Ref to billing doc

    Hello all. When I create a SO w/ SaType 'A' it picks the correct Pricing procedure. However if I were to create the same Order Type 'A' w/ reference to a billing doc it picks up the Pricing procedure of the billing doc and not the one assigned to it

  • Reports in Character Mode - Can I generate a PDF?

    Hi, i'm working with Forms 6i in Character Mode. Forms and Reports are in Unix Server. Now, all the forms call the reports like this: run_product(REPORTS, lower(lv_reporte), SYNCHRONOUS, BATCH, FILESYSTEM, list_id, null); HOST('sh imprime '||lv_salid

  • Processing Pattern task runs multiple times

    I am trying out the processing pattern with some long running tasks. The tasks are submitted by the first node in the cluster to start up. I seem to see multiple copies of my task running as I start up other nodes in the cluster. It would appear that

  • Mac Mini says no airport installed

    ok so i have a mac mini that i just upgraded from 10.4.11 to os x 10.5.6 and for some reason my wifi(airport card or whatever) is not being detected also no Bluetooth only Ethernet and fire-wire do i have to update, install drivers or what.before i u