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

Similar Messages

  • How to execute *.BAT file from  the Java Application

    Hello to all.
    I wants to run *.BAT file form my applicaion.
    Can u give the code of that two-four line,please
    Wating four your replay.
    Yours Friend
    Bhavin Shah.....

    pr = rt.exec("cmd.exe /c start " + yourProgramName)The exec() method executes the command you specify in the argument and returns a process. In this example, it's telling Windows to run "yourProgramName".
    HTH

  • Executing *.bat file from PL/SQL

    Is there anyway for Executing *.bat file from PL/SQL ?
    Thanks

    Try here:
    asktom.oracle.com/pls/ask/f?p=4950:8:15427268967155079552::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241

  • Execute .Bat file from pl/sql code

    Hi,
    Can you please let me know that how can I execute the .Bat file from pl/sql procedure? Does anybody have a sample code??
    Thanks.

    Hi
    This may help you
    http://www.dba-oracle.com/t_running_windows_bat_file_dbms_scheduler.htm
    br,Jari

  • Executing another exe from a java class

    Hi All,
    I want to execute another executable from a java class. I am doing that with the help of Runtime.getRuntime().exec(String) function.
    My executable runs for quite sometime and it keeps printing something to stdout consistently.
    I want to read whatever this exe is putting out to stdout as and when it is put out, not after the whole process has finished.
    Now, Runtime.getRuntime().exec(String) just spawns the exe in another process space and I am not able to get its handle, maybe I have missed something.
    Is there any other method/way to do what I want to?
    TIA
    -Satish

    Now, Runtime.getRuntime().exec(String) just spawns the
    exe in another process space and I am not able to get
    its handle, maybe I have missed something.
    Is there any other method/way to do what I want to?Acutally, Runtime.getRuntime().exec(String) returns a Process object. Use this process to "talk" to the program you just launched. For your needs, try Process.getOutputStream(). Take a look at the API for Process at http://java.sun.com/j2se/1.3/docs/api/java/lang/Process.html
    Hope this helps.

  • 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
    }

  • Reading files from within helper classes

    From within a servlet, I can get the servlet context to get a path to the "web" directory of my project and easily access properties files for my project. If I create another package in my project to hold helper classes that perform some specific function and want to create and/or read from a properties file, I get a path to the bin directory of my servlet container:
    Servlet Path: D:\Documents and Settings\Josh\My Documents\Josh\Projects\ServletSandBox\build\web\
    Helper Class File Path: D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test
    I'd like to develop my helper packages as reusable APIs, so they're not tied directly to my project or to a servlet in general, but I'd like the properties files to stay somewhere in my project folder, preferably in the WEB-INF directory with the servlet's own specific properties file.
    I can't figure out the best way to handle this. I wanted to just be able to pass the helper class a String if somebody wanted to specify a filename other than the default filename. Does it make sense to specify a file URL instead? Is there any other way to get the calling servlet's context path without having to pass in a variable?
    Thanks

    It seems that the helper API shouldn't need to be given a path to its own config file. I would like to have code that will load the file regardless of whether or not its in a stand alone java app or a servlet. Whenever the helper API is jarred up and imported into my servlet, it can't find the config file unless it's in the "D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test" directory. OR, if I use the current thread to get the loader, it will locate it in the "classes" folder, which is the only solution I can come up with that will let me write code to load the file that will work, regardless of its implementation.
    The "project" folder I'm talking about is just the NetBeans "project" folder for the servlet, or the "ServetSandBox" folder in my example. I guess that doesn't really matter in the context of the servlet though.
    So is using the current thread the appropriate way to do this? When you say that code will work if I put the resource in the WEB-INF directory, that seems to only be true if I try to load it from the servlet itself, not the helper class. The helper class doesn't find the resource in the WEB-INF directory.
    Also, I would like to be able to write the default values to a new config file if one doesn't exist. How in the heck do I get a pointer to the "classes" folder, or any other folder that I can also read from using the classloader, so I can write to a new file?

  • How to Run a .sql file from simple java class

    How to execute a .sql file consisting of Complex Queries,procedures through simple java class.
    The queries may have different delimiters,queries independant of each other.
    I am able to do with Specific De-limiter.But I need in such a way that there should not be any
    Constraints. Since My .sql may Contain different De-limiters.
    If any one can Suggest Some Solution.
    It will be Great Help.
    regards
    Anil

    Check out ibatis script runner, it' a third party library but quite handy for running sql files...
    m

  • 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)

  • Creating windows .bat file from within an oracle .prc or .sql file

    I am currently converting a series of batch jobs on a windows server to use an Oracle db rather than a MS sql server db. In ms sql, I could call \mssql80\binn\isql and it allowed me to pass in .prc files and have a .bat file returned. the .bat file is then executed in the calling bat to set variable value returned in the sql call...
    I am thinking I can spool a bat file, however, i do not know how to populate this file with the literals and query values needed to create the bat file which sets values used for further processing in the original calling bat file...
    Does that make sense? any help is greatly appreciated.

    Hi,
    There can be various ways to do this.
    First and simple way is simply spooling out the batch file. Suppose you have a .sql file with all the queries, run the .sql from DOS prompt like this,
    c:\> sqlplus -s username/password@tnsname @mysqlfile.sql
    the contents of mysqlfile.sql can be,
    rem ---------------------
    set echo off feedback off head off
    spool c:\batch_files\mybatch.bat
    select 'start \w ' || win_app_name from mytable ;
    spool off
    rem ----------------------
    exit
    So, you can get the batch file created with desired name in desired directory. The '-s' mentioned in the sqlplus command is important.
    There is another difficult/tedious way, but that can give you exact output. With UTL_FILE package you can write an operating system file from pl/sql code, stored procedure/package. Its look more like C-language code, but is usefull. So, write a sql or stored procedure and create the batch file. For that matter, you can write any type of file, just you can write whatever you want to a file.
    Cheers

  • Executing bat files from another location

    Hi
    In my application i need to execute a bat file which is in another location.
    i have my class file in c:\ds and i want to execute the bat file in c:\ds\src\jython.
    This is the code i have used
    private void executeBootstrapBat(){
    String cmd=null;
    cmd="cmd /c bootstrap C:\\DS\\HelperApplication\\src\\conf\\wsadmin-local.properties" +
    " " + getXmlFileName() + " " + getVOB();
    Runtime rt = Runtime.getRuntime();
    try{
    Process pt = rt.exec(cmd);
    }catch(IOException e){
    e.printStackTrace();
    }

    You can execute the bat file in any location. Butyou
    have to set the classpath in that location whereyou
    are executing the bat file.Please stop giving advice on this site. You do not
    have any clue what you are talking about at all.Actually I just went looked at a few more of your posts. All complete rubbish. Again please stop posting replies on this site until you get some clue about anything. It is very wrong of you to post replies like you know what you are doing and misleading those who don't know any better.

  • Executing DOS command from within java.

    I have an XML file and an XSLT stylesheet.
    I want to process this XML file using XSLT stylesheet from java. Using saxon.
    Here is the java class I wrote --
    class DOSCommand {
    public void exec_command(String[] cmd) {
    try {
    Process child = Runtime.getRuntime().exec(cmd);
    } catch (IOException e){
    System.out.println("Error");
    System.out.println(e.getMessage());
    finally{
    System.out.println("Finally");
    In my servlet class I am instantiating the DOSCommand object and calling the method
    DOSCommand d = new DOSCommand();
    String[] c = {  "c:\\Program Files\\saxon\\saxon.exe", "-o",
    "PO.html", "ePO.xml", "POE.xsl"
    d.exec_command(c);
    But I am not getting results. It does not give any error. But does not process the XML file and the Date/timestamp of PO.html does not change.
    I know that Definition/Creation of DOSCommand object is not necesssary here. But we can disregard it.
    Please let me know where I am going wrong !
    Avinash.

    Probably where you are going wrong is in failing to specify your working directory, so your command can't find "PO.html" and so on in the default working directory for that command. But that's not really the answer. The answer is not to do it in that way in the first place. Saxon has a Java API and its documentation has a section entitled "Embedding Saxon in an application".

  • How to find path from within java class where .class file is located

    I have a situation where my Servlet is running.
    I need to access a text file which is locted in the same
    place where the .class file for this Servlet is located.
    I cannot specify absolute path in my java file.
    I am in Windows platform.
    My filename is specified as
    File("myfile.txt");
    the problem is it says file not found.
    how do i fix this prob?
    thanks in advance

    String filename="/relative_path/file_name.txt";
    try {
       //static method approach
       InputStream is = YourClassName.class.getResourceAsStream(filename);
       //non-static method approach
       InputStream is = getClass().getResourceAsStream(filename);
    } catch (IOException e) { ... }tajenkins

  • 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 to make an exe file from a java class file

    i know one of the java's most powerfull properties is plataform independent, but if i have done one application (with GUI) that i want to run on Win32 for example, if anyone knows how to make it please send me a message to [email protected], how i know that can be make it? because HotJava is made in Java and in Win32 is a executable

    Do a search on these forums for any of the thousands of times this question has been asked and any of the thousands of times it's been answered.

Maybe you are looking for

  • Where can I find the Start up disk and how can I delete file from it.

    where can I find the Start up disk on theMac Book Air? How can I delete files from it?

  • Desktop agent keeps initalizing, cannot uninstall either

    For a few weeks now my Desktop agent keeps initalizing and it kicks me out of the supervisor console. When I try to install another version it says "A conflicting application has been detected. See product documentation for a listing of valid configu

  • Is Java3D not supported by sun anymore?

    Hi i was just reading a thread in this forum that said that java 3d is not supported by sun anymore. Can somebody please confirm for me. This is the thread: http://forum.java.sun.com/thread.jsp?forum=21&thread=459570&tstart=0&trange=15

  • Windows 8.1 configure app listings.

    The Start page has a downward pointing arrow which reveals list fo installed apps.   Is it possible to define my own headings and then move apps to the list I feel appropriate?    Fences software offers this sort of facility but on the desktop rather

  • Why are my embedded SWFs so ugly?

    Hello people, When I embed my swf file into my website (running on Wordpress), it looks ugly, Round picture elements (which come from PSDs, incidentally) show up jagged and ugly on my webpage, even though I use the best quality settings. I've tried t