1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

run a exe file by java code

Discussion in 'Java' started by nadunalexander, May 6, 2007.

  1. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    I have written a simple html editor in java. I have to open my html page in internet explorer when I click preview button in my application. to open my html page in internet explorer programmatically? any one can help me
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    If its a Windows system where the Java application runs, use this

    Code:
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
    // url is the URL u want to open
    
     
  3. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    can u explain little bit more? my html file path is "C:\myPage.htm". when I type this ide show a error illegal escape charectar.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Code:
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "C:\\myPage.htm");
    // url is the URL u want to open 
    
    You have to escape the slash in the path!
     
  5. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Thank you very much for ur help. I like to use applications programatically. for an example I have to open a word file and draw a line programatically. Can I do this task by java or any programming language?
     
  6. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
  7. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
  8. diyarana

    diyarana New Member

    Joined:
    May 5, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "C:\\sample.exe");
    using this code I have open an exe file from java....

    Now I want to open the same exe by passing two parameters....open a C source code and a file to redirect the output....

    How can I do that?
     
  9. gkumar

    gkumar New Member

    Joined:
    Jun 16, 2009
    Messages:
    58
    Likes Received:
    5
    Trophy Points:
    0
    In this coding to execute exe from java file.

    Code:
    import java.lang.*;
    import java.io.*;
    
    public class LoadNotpad{
      public static void main(String args[])throws IOException{
        Runtime r=Runtime.getRuntime();
        Process p=null;
        try
        {
          String s="c:\\windows\\notpad.exe";
          p=r.exec(s);
        }
        catch(Exception e){
          System.out.println("error==="+e.getMessage());
          e.printStackTrace();
        }
      }
    }
    
    /*This is the exception when i am running the above code plz help me to execute
    this code and the mentioned java file Win32Process is not in my jdk1.2.2 */
    /*
    java.io.IOException: CreateProcess: c:\windows\notpad.exe error=0
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:64)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:272)
    at java.lang.Runtime.exec(Runtime.java:195)
    at java.lang.Runtime.exec(Runtime.java:152)
    at LoadNotpad.main(LoadNotpad.java:11)
    Tool completed with exit code 1
    */
    
     
  10. sundaravigneshvaran

    sundaravigneshvaran New Member

    Joined:
    Mar 28, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    Just check your spelling mistake

    'notpad.exe'

    change it notepad.exe
    bye
     
  11. jasirjamal

    jasirjamal New Member

    Joined:
    Apr 27, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I wanted to know how to open an exe file from a java project, that is at a click of a button
     

Share This Page