Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: run an external program

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default run an external program

    Hi all, I ask here also if I'm not sure is a Swing problem...but no idea where this question can go...

    So : I have a java program that read a .xml file. This xml file is created by another program ( pdftohtml.exe).

    now if I use the console( eclipse ) then I can get the .exe run and generate the xml file I need... with this:
    	private void convert() {
    		try {
    			Runtime rt = Runtime.getRuntime();
     
    			File my_file = new File(tP);
    			my_file.mkdirs();
     
    			File my_file2 = new File(tP + "\\pdf2xml.dtd");
    			this.fos = new FileOutputStream(my_file2);
    			this.osw = new OutputStreamWriter(this.fos);
    			build_dtd();
     
    			String cmd = "pdftohtml -xml " + sP + " " + tP + "\\data";
     
    			Process p = rt.exec(cmd);
    			p.waitFor();
    		} catch (Exception e) {
    			new Warning(e.getMessage(), true);
    		}
     
    	}

    Now I have done a GUI and I have build an executable .jar file...
    The problem is that now the program doesn't work... it tell me that the .exe file can not be found and so the xml is not generated and so my program is not working...

    I hope that the problem is clear and that someone can help me...

    by all


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: run an external program

    the .exe file can not be found
    Is the .exe file on the OS's path so it can find it? Open a command prompt change to a folder without the .exe file and enter the name of the .exe to see if the OS can find the .exe file.
    How is the .exe found when you execute the program from your IDE? Is it in a local folder?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: run an external program

    Hi, yes...the .exe file is on the workspace program folder ( but I have also tried to put it in the src/programm/file.exe (where there is also the .java class that use it) and tried to load using : String cmd = pdfXmlConverter.class.getResource("pdftohtml.exe") .getPath()+" -xml " + sP + " " + tP + "\\data"; to locate it...) as before it work when I run the program from eclipse...and doesn't work when packed in runnable .jar and launched...

  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: run an external program

    Hi, I'm really sorry for this stupid question...

    the problem was that we need to place the .exe file in the same directory where there is the .jar .

    Thank you very much...

    See you soon...

    By...

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: run an external program

    The OS will not try to execute a .exe file from inside of a jar file.

    For testing try copying the jar file and the .exe file to a empty testing folder and open the jar file to see if it finds the .exe file when it is in the same folder as the jar file.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Embedding Java application into external client
    By 1372586 in forum Java Networking
    Replies: 3
    Last Post: November 3rd, 2011, 08:57 AM
  2. Accessing an external JAR file using Applet
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 28th, 2011, 12:51 AM
  3. Zipping External Libraries With Jar
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: March 31st, 2011, 08:49 PM
  4. Running a external exe in Mac OS
    By supertreta in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 15th, 2010, 01:32 PM
  5. Interaction with external application
    By righi in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 2nd, 2010, 08:37 AM