Re: Calling foreign executables

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 12/17/03

  • Next message: Daniel Bonniot: "Re: which foo(x)"
    Date: Wed, 17 Dec 2003 19:27:19 GMT
    
    

    "Hrvoje Somun" <hrvoje.somunREMOVE@zg.tel.hr> wrote in message
    news:brq5mr$pch$1@sunce.iskon.hr...
    >
    > How can i call some other program from java application?
    >
    > let say i want to call iexplorer('iexplore' from command line)...
    > thnx
    >

    You may care to try the code below.

    I hope this helps.

    Anthony Borla

    // ---------------------------------------------

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    public class LaunchIE
    {
      public static void main(String[] args)
      {
        if (args.length < 1)
        {
          System.err.println("Usage: java LaunchIE filename");
          System.exit(1);
        }

        try
        {
          viewFile(new File(args[0]));
        }

        catch (FileNotFoundException e)
        {
          System.err.println("File could not be located, or does not exist");
        }

        catch (IOException e)
        {
          System.err.println("File could not be opened");
        }
      }

      // Win32-specific Code
      public static void viewFile(File file)
        throws FileNotFoundException, IOException
      {
        if (!file.isFile())
          throw new FileNotFoundException();

        StringBuffer cmd =
          new StringBuffer("rundll32 SHELL32.DLL,ShellExec_RunDLL ");

        cmd.append(file.getAbsolutePath());

        Runtime.getRuntime().exec(cmd.toString());
      }
    }

    // --------------------------------------------


  • Next message: Daniel Bonniot: "Re: which foo(x)"

    Relevant Pages

    • Re: Simple program not producing output
      ... Pasted the MSDN code into this code file. ... When to a command shell, located the exe. ... public static void PrintValues ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Simple program not producing output
      ... Pasted the MSDN code into this code file. ... When to a command shell, located the exe. ... public static void PrintValues ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: alias
      ... feel the need to do something like this for typing much less, ... // alias, creating short hand for some commonly used command, DL ... public static void o{ ... There are also convenience methods in the outputstreams: ...
      (comp.lang.java.programmer)
    • Re: Capturing output from a command
      ... > command that I am using, while it runs fine from the dos ... May I point out that unless this is purely a Java learning exercise, ... are third party tools such as sed / grep and gawk. ... public static void traceIP ...
      (comp.lang.java.help)
    • Re: Indentation (Re: finally block does not complete normally - Eclipse)
      ... >>> brace style. ... // {Args: A B C} ... * taken from the command line. ... public static void main{ ...
      (comp.lang.java.programmer)