Executing an HTML file from within Java

My program produces a file of run statistics formatted as html (stats.htm).
I want to execute this file in a browser from within my program - ie. call a browser with this file as a parm.
How do I do that ?
Have tried executing a DOS command for the form "cmd /C fullpathname-of-file" but it does nothung.
Thanks
...KenR

Thank you very much...that worked file.
The relevant code is:
String arg = "G:/tma03/agents/stats.htm";
java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); ...to set-up Desktop object
try ... to create a URI object using arg
java.net.URI uri = new java.net.URI( arg );
desktop.browse( uri ); ... to browse the URI
}

Similar Messages

  • Executing a perl script from within java application

    Hi,
    Does anyone knows a way to execute a perl script from within java.
    ---kirk

    Runtime.exec("perl myscript.pl");
    Of course whether that "works" depends on what the script does and where the java program runs.

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • Running other binaries or batch files from within java

    Hello,
    I recently inherited several closed-source windows executables. I need to execute them when a user clicks on a JButton. (after which I can parse the text files they generate)
    I realize this will make my application windows-only...
    Does anyone know how I can execute a file (or dos shell commands) from inside java?
    Thank you in advance,
    Andy

    My understanding was the command.com (which isn't an executable, just like dir isn't an executable (not a windows user, doesn't know these things))
    "Not to be confused with OS/2 Warp CMD.EXE, the file CMD.EXE is the Microsoft Windows NT command line shell and is more compatible and portable between different hardware platforms when compared to the original COMMAND.COM, which has been used as the command interpreter with DOS for several years. COMMAND.COM is included for backwards compatibility and is recommended that it be used when old MS-DOS programs may not be able to be run in Windows NT."
    "Apart from what was listed in the opening paragraph, one of the most noticeable things a user is going to notice when using CMD to access MS-DOS is the ability to use long file names. When a user is using COMMAND they will need to use the short 8.3 name. For example, if a user wanted to access "My Documents" in COMMAND they would need to type "cd mydocu~1". However, a user who wanted access the same directory through CMD could type "cd my documents"."
    I believe my legacy software falls in to the category of "old MS-DOS programs" (and the Windows XP kernel is based on NT)

  • Iam not able to run a simple batch file from within java

    This is how my code looks like.
    It does'nt give me any error but I dont see the output from batch file which is suposed to be a simple redirection of dir command...
    package mypackage1;
    import java.io.File;
    public class RunBatch
    public RunBatch()
    try{
    Runtime rt = Runtime.getRuntime();
    String cmd = "generate_invoice";
    String path = "C:\\application\\Maps\\Reports";
    File file = new File(path);
    String[] envp = {""};
    String[] args = {"C:\\application\\Maps\\Reports\\generate_invoice.bat"};
    System.out.println("************ executing batch ");
    Process proc = rt.exec(args);
    System.out.println("************ batch executed ");
    }catch(Exception e)
    e.printStackTrace();
    * @param args
    public static void main(String[] args)
    RunBatch runBatch = new RunBatch();
    }

    Runtime.exec() only can run executable files. Batch file is not an executable - it is a script executed by command interpreter (cmd.exe). So, you should execute "c:\windows\system32\cmd.exe /c C:\application\Maps\Reports\generate_invoice.bat".
    Denis
    http://www.excelsior-usa.com/jet.html
    JVM with AOT compilation

  • How can I execute a  .bat  file from inside a java application

    I have a .bat file which contains an executable file(.exe) and some input and output file names. What commands can I use to execute this bat file from my java application.

    After raeding tkleisas' reply; i am trying to invoke another application (which can be invoked from the command line) by using a batch file and trying Runtime.exec for executing a batch file.
    My current code is:
    Runtime runtime = Runtime.getRuntime();
    Process trialProcess;
    trialProcess = runtime.exec("cmd.exe /C start C:\\guns.bat /B");
    And my guns.bat looks like:
    cd C:\CALPUFF
    echo trial
    start calpuff.exe CALPUFF.INP
    This is not working for me and i get the following in the error stream of the trialProcess:
    Error :
    The system cannot execute the specified program.
    Process finished with exit code 1
    Has anyone come across something like this and know what's wrong with this one??
    thnx

  • Write HTML Files from java application

    Hello,
    i have to write HTML files from a java application.
    I am asking if anybody can give me a hint about a good simple solution (library) which can do some of the job for me.
    i know FOP for example is good to create pdf or html from xml, but i dont want to go via xml.
    the sites i need are really very simple presents emails.
    body and maybe a link for next and pervious.
    however, thank you in advance.
    a little hint will also help :)
    Sako.

    That, too, is my question.
    Be the "server" local or remote, wouldn't JSPs still
    be the easier solution? No. it will not. because you need a server. Server for a stand alone application is not esier. according to who said JSPs are easy?
    Its very very difficult.
    >
    When answering, please clarify. I'm a bit of a newbie
    here. :)To get sence about how hard is JSP, check Struts. this is very good open source Framework to simplify the JSPs. but it still complecated enough.
    or Tapestry my lovely open srouce Framework.
    its easier than Struts. but sill complecated because of the documentation.
    All in all, using JSP is the purpose of Java in the internet. but not for me. My application will not be available in the internet, i.e. no server, i.e. no need for JSP.
    i hope that helps a little.

  • How to run .html file from .java file..?

    Hi All,
    I was just trying as mentioned in the subject of how to run an html file from a java file.We have runtime class which inturn is having exec method which returns process but it supports only .exe as an argument .Is there any way to do this???
    Thanks in advance.

    viswa07 wrote:
    You mean to say Desktop class in java...???I'm so sorry, I thought you knew enough Java to look up the API.
    [This link|http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html] might be more at your level.
    db

  • How to run a batch file from within an Oracle 9i Form?

    Hi, I would like to execute a batch file from within an oracle form - I'm assuming there's some PLSQL command I can use? I am not allowed to use any third party libraries, and I'm hoping I can get away without having to progam any C or Java to do it. I don't want to run my java program from my form, but my lecturer is insisting on it.
    Can anyone help?
    Thanx
    Adam

    Can u give me an example
    I need to run a batch files that does a series of step doing dir ( in 3 different folders)
    after each one it shows on screen with a pause & user press enter
    can this work out ?

  • Executing an HTML file within java program

    I want my java code to be able to open/execute an HTML file that I have. How do you do this?
    Thanks.

    You can display html in a java app, but it is not so simple to run a browser. What you want to look up is the WebBrowser class. Here is an excerpt from some code of mine that displays a url in the browser app in a panel, but there's some chaff in my code you would not be interested in (I'm using a card layout). You're better off loocing up org.jdesktop.jdic.browser which contains the WebBrowser class    /**
         * Reveal the container with the browser display. The browser display is
         * currently hidded using a CardLayout, so it is a simple matter to swap
         * displays; however, we put off actually loading the web page until the
         * first time the display is revealed.
         * @return true if the URL could be resolved and the given web page
         * displayed.
        public boolean showBrowser(
            java.net.URL pURL )
            // See if the web page component has not initialized.
            if ( pWebBrowser == null )
                pWebBrowser = new WebBrowser();
                pBrowserPane.setViewportView( pWebBrowser );
            if ( aLastURLVisited == null || ! aLastURLVisited.equals( pURL ) )
                pWebBrowser.refresh();
                pWebBrowser.setURL( pURL );
                aLastURLVisited = pURL;
            pDualLayout.show( pDualPanel, BROWSER_PANEL );
            return true;
        }

  • Execute html file from java code - urgent!!!

    Hi,
    I need help!!
    My application should open html file that located in my computer
    it should be open when some line in JList was choosen
    my question is: How can I open html file from my application
    I work with window XP
    I tried this one :
    Runtime.getRuntime().exec(cmdLine);
    but it doesn't work
    the exeption was: CreateProccess
    Please help! it's urgent!!!!

    http://forum.java.sun.com/thread.jsp?forum=31&thread=497600

  • Executing class files from a Java App dynamically

    Hi!, Is there any way i can execute java .class files from my Java Application dynamically. I know that java uses Dynamic method Invocation. Is that true of class files generated using some other language compiled for the JVM.
    In my case i would like to make a Web browser that interprets HTML and also java applets embeded in them. I would like to use the JRE of the platform execute the applets for me rather than writing the code for my Browser to interpret the class files.
    Thanks in Advance.

    You just need a custom class loader to bring these applets into your JVM.
    http://developer.java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/URLClassLoader/index.html
    Then you can use the methods of java.lang.Class to create an instance of such a class. As soon as you have it, you can just treat it as a regular Applet and invoke init(), stop() etc. appropriately.
    If you want to execute anything else than conventional Applets, you might consider reflection to find out about methods implemented:
    http://java.sun.com/docs/books/tutorial/reflect/index.html

  • How to create windows executable file from a java file. Please help.

    Hi,
    For my project I developed the codes in Java. It is working well with java run time environment. But without that I can not run it. I need to create a exe file (windows executable file) from the java source code. If you have any idea please share it with me.
    Even if you know it very lightly, please help with what you know. That would be a big help for me.
    Thank you very much.

    Does anybody know how to read a manual?
    Matt Richardson
    Certified LabVIEW Developer
    MSR Consulting, LLC

  • Possible to create a JAR file from within a java app?

    Is it possible to create a jar file from within a java application?
    Can it be done more elegantly than by spawning-off another
    process with the Runtime and exec() portions of the api?
    Thanks
    Scott

    Thanks! I was mislead by the API notes for java.util.jar:
    The JarOutputStream class is used to write the contents
    of a JAR file to any output stream.
    I was looking for a class or method to make jar files.
    Seems this is it ;)
    Thanks
    Scott

Maybe you are looking for