Call .bat file from java code

I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
importcli.exe db1800 C:\Importcli\files\*.mdb

magaupe wrote:
I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
importcli.exe db1800 C:\Importcli\files\*.mdb
Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
[http://www.google.com/search?hl=en&q=call+.bat+file+from+java]

Similar Messages

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • Running .bat files from java code

    Dear Forum,
    I have seen numerous postings on the web about this question, still I have found no answer that works (for me)
    I�m trying to run a simple .bat file from a piece of java code , however it does not work. No error message , but still.
    Does anyone have a tip?
    best regards
    temuj
    try{
                String cmd = "cmd.exe C:\\mybat.bat";
                Runtime.getRuntime().exec(cmd);
    catch(IOException e){System.out.println("ERROR: "+e);}Message was edited by:
    temujin

    "cmd.exe C:\mybat.bat" is being passed to the OS for execution
    what happens when in a terminal/dos window you execute letter for letter:
    cmd.exe C:\mybat.bat
    The output will be identical to what is happening when java makes this call.

  • Executing a .bat file from java code

    Im writing a utility and i need to be able to create and execute a .bat file from my program. I can create the .bat file fine but when i try to execute it nothing happens. I tried to use the following line of code to try to execute the .bat file (called make.bat) :
    try
    String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" C:\\ITS_Test\\make.bat";
    Runtime.getRuntime().exec(parameterString);
    catch (Exception e)
    System.out.println(e);
    The Runtime.getRuntime()exec() method worked fine when trying to execute an excel file but for some reason it dosen't want to work for the DOS prompt. Any ideas?

    Thanks everyone for all the replies.
    I have tried all the above with no luck. Im using netbeans, does anyone think that it could be a problem with the IDE.
    I tired the following code :
    String parameterString = "cmd.exe /C \"C:\\ITS_Test\\make.bat\"";
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    This code does not throw any exceptions but just hangs. I also tried:
    String [] parameterString = {"cmd", "/c", "C:\\ITS_Test\\make.bat"};
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    and:
    String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" \"C:\\ITS_Test\\make.bat\"";
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    with the same result. Does anyone know why it just hangs and nothing happens (no exceptions thrown)?

  • Running Oracle startup or shutdown bat file from Java code

    I have two bat files for the startup and shutdown of Oracle instance which works fine from the command prompt. But my requirement is to run it through a Java program. Please reply with full Java code. Also mention how I would get the status of the bat files that it is successfully executed or not and if not what is the error.

    Your program is working fine, but there is another problem. What's happening now is I have to open the Login screen after the startup of oracle server is complete, but the next line of my program after Runtime.exec is the LoginScreen.show which immediately shows the login screen after executing Runtime.exec and when I am giving the login name and password and press enter, it shows Oracle not available exception, because the startup process is still in progress. I want to stop the execution of my next line of code until and unless my process of Oracle startup is complete.

  • Starting exetutable java file from java code

    Hi I was wondering how I can start a executable java file from java code?
    thanks

    Hi Mkaveli,
    Yes, it's possible. If you have a JAR executable, you've just to call the main method of its starter class. For a simple executable class, just call its main method.
    This way :
    SomeStarter.main(null); // if there's no argumentSmall precision : the executable JAR or class must be specified in the classpath of your application.

  • Running bat files in java code

    Hi,
    I am trying to run a .bat file within java code like this.
    Runtime.getRuntime().exec("c:\\Test.bat");
    but no success. Could you please suggest how to run .bat file or simply a
    DOS command from java code.
    thanx in advance
    Deepak Garg.

    try this...
    n reply whether it worked or not......
    import java.util.*;
    import java.io.*;
    import java.net.*;
    try
    Runtime runtime = Runtime.getRuntime();
    Process process ;
    process= runtime.exec("./temp_install");
    //code to print command line replies
    InputStream stderr = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while((line=br.readLine())!=null)
    System.out.println(line);
    catch(Throwable t)
    t.printStackTrace();
    }

  • Generation of xml file from java code

    hi,
    I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?

    Let me know which parser are you using currently for reading xml files so that i assist you. For now, you can refer to STAX Parser API under this link
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

  • I wants to call .Exe file from Java Programme

    I wants to call .Exe file from Java programme. Please give answer with example. This very urgent. Help me

    hi
    u can use Runtime.exec() method in java.lang package
    to execute exe files
    regards
    pnp

  • How to Call .XDO file From Java Program

    Hi,
    I have developed a report in using BI Publisher version 10.1.3.
    I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
    What are the APIs available to do that.
    Thanks
    -Ashutosh

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • How to call a exe or bat file from java program

    hi,
    i actually want to know that how to call a exe or bat file from program so that i can run them parallely.

    Try this :
    String strCmd = "myFile.bat";
    try
         Runtime rTime = Runtime.getRuntime();
         Process process = rTime.exec(strCmd);
         InputStream p_in = process.getInputStream();
         OutputStream p_out = process.getOutputStream();
         InputStream p_err = process.getErrorStream();
         p_in.close();
         p_out.close();
         p_err.close();
    catch(Exception e) {
         throw new Exception("Unable to start, "+strCmd);
    }

  • How to pass arguments to a batch file from java code

    Hi
    I have a batch file (marcxml.bat) which has the following excerpt :
    @echo off
    if x==%1x goto howto
    java -cp C:\Downloads\Marcxml\marc4j.jar; C:\Downloads\Marcxml\marcxml.jar; %1 %2 %3
    goto end
    I'm calling this batch file from a java code with the following line of code:
    Process p = Runtime.getRuntime().exec("cmd /c start C:/Downloads/Marcxml/marcxml.bat");
    so ,that invokes the batch file.Till that point its ok.
    since the batch file accpets arguments(%1 %2 %3) how do i pass those arguments to the batch file from my code ...???
    %1 is a classname : for ex: gov.loc.marcxml.MARC21slim2MARC
    %2 is the name of the input file for ex : C:/Downloads/Marcxml/source.xml
    %3 is the name of the output file for ex: C:/Downloads/Marcxml/target.mrc
    could someone help me...
    if i include these parameters too along with the above line of code i.e
    Process p = Runtime.getRuntime().exec("cmd /c start C:/Downloads/Marcxml/marcxml.bat gov.loc.marcxml.MARC21slim2MARC C:\\Downloads\\Marcxml\\source.xml C:\\Downloads\\Marcxml\\target.mrc") ;
    I get the following error :
    Exception in thread main java.lang.Noclassdef foundError: c:Downloads\marcxml\source/xml
    could some one tell me if i'm doing the right way in passing the arguments to the batch file if not what is the right way??
    Message was edited by:
    justunme1

    1 - create a java class (Executer.java) for example:
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    public class Executer {
         public static void main(String[] args) {
              try {
                   for (int i = 0; i < args.length; i++) {
                        System.out.println(args);
                   Class<?> c = Class.forName(args[0]);
                   Class[] argTypes = new Class[] { String[].class };
                   Method main = c.getDeclaredMethod("main", argTypes);
                   // String[] mainArgs = Arrays.copyOfRange(args, 1, args.length); //JDK 6
                   //jdk <6
                   String[] mainArgs = new String[args.length - 1];
                   for (int i = 0; i < mainArgs.length; i++) {
                        mainArgs[i] = args[i + 1];
                   main.invoke(null, (Object) mainArgs);
                   // production code should handle these exceptions more gracefully
              } catch (ClassNotFoundException x) {
                   x.printStackTrace();
              } catch (NoSuchMethodException x) {
                   x.printStackTrace();
              } catch (IllegalAccessException x) {
                   x.printStackTrace();
              } catch (InvocationTargetException x) {
                   x.printStackTrace();
              } catch (Exception e) {
                   e.printStackTrace();
    2 - create a .bat file:
    @echo off
    java -cp C:\Downloads\Marcxml\marc4j.jar; C:\Downloads\Marcxml\marcxml.jar; Executer %TARGET_CLASS% %IN_FILE% %OUT_FILE%3 - use set command to pass variable:
    Open MS-DOS, and type the following:
    set TARGET_CLASS=MyTargetClass
    set IN_FILE=in.txt
    set OUT_FILE=out.txt
    Then run your .bat file (in the same ms dos window)
    Hope that Helps

  • Running bat-files from Java

    Hello,
    I have been trying to launch a bat-file from my Java code, running under windows, but with no success.
    Here is my simple code:
    Runtime.getRuntime().exec(new String[] {
             "C:\\temp\\test.bat"
          });This does nothing at all and generates no exception. Any suggestions?

    It seems java has a real problem with this... if you
    want to run another java program, for instance, you
    cannot do that either with String cmd="cmd.exe /C
    java myProgram"
    I need to pass parameters from one program into the
    program I'm going to open using java, that is why I
    need to call it from my first program. It can open
    executables and shortcuts, but has a real big problem
    doing things with the command line.No it doesn't have a problem with it. You just must be doing something wrong. By the way, since "java(.exe)" is already an executable, there's little value in wrapping that by the "cmd.exe" shell (unless you want to use the command shell for some reason such as passing the redirector (>) symbols to it to let it redirect stdout / stderr to a file)

  • Calling .bat file from pl/sql

    I'm running Oracle 11g R2 on win7 system, and I would like to execute .bat file from a pl/sql block.
    I created a .bat file
    I have granted privs to an account:
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON', permission_type   => 'SYS:java.io.FilePermission', permission_name   => '<<ALL FILES>>', permission_action => 'execute',key => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type   => 'SYS:java.lang.RuntimePermission',permission_name   => 'writeFileDescriptor',permission_action => '*',key => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type   => 'SYS:java.lang.RuntimePermission',permission_name   => 'readFileDescriptor',permission_action => '*' ,key => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type   => 'SYS:java.io.FilePermission',permission_name   => 'C:\dokumentacija\rman_backup\*',permission_action => 'read,write',key => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type   => 'SYS:java.io.FilePermission',permission_name   => 'C:\dokumentacija\rman_backup\*', permission_action => 'read',key => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON', permission_type   => 'SYS:java.io.FilePermission', permission_name   => 'C:\windows\system32\*',permission_action => 'read',key   => KEYNUM);
    END;
    DECLARE
    KEYNUM NUMBER;
    BEGIN
      SYS.DBMS_JAVA.GRANT_PERMISSION(grantee=> 'COMMON',permission_type   => 'SYS:java.io.FilePermission',permission_name   => 'C:\windows\system32\*',permission_action => 'execute',key => KEYNUM);
    END;
    /this is Java:
    CREATE OR REPLACE PROCEDURE runoscommand(cmd IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Command.run(java.lang.String)';and this is how I call it:
    declare
    xx pls_integer;
    v_errm varchar2(400);
    begin
    xx:=0;
    xx:=archiver.fullBackup;
    dbms_output.put_line(xx);
    exception
        when others then
        v_errm:=substr(sqlerrm,1,400);
        dbms_output.put_line(v_errm);
    end;this is Java code:
    DROP JAVA SOURCE COMMON.COMMAND;
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED COMMON.COMMAND as import java.io.*;
    import java.util.*;
    public class Command{
    public static void run(String cmdText)
                         throws IOException, InterruptedException
      int rtn;
           Runtime rt = Runtime.getRuntime();
      Process prcs = rt.exec(cmdText);
      rtn =  prcs.waitFor();
    }I run this as a part of a package...
    function fullBackup return pls_integer as
    v_errm varchar2(200);
    begin
        runoscommand('C:\dokumentacija\rman_backup\bckp_level_0.bat');
        return 0;
    exception
        when others then
            v_errm:=substr(sqlerrm, 1,200);
            dbms_output.put_line(v_errm);
            return -1;
    end fullBackup;but..
    at the end, nothing happens..
    what I've been missing?

    846417 wrote:
    I changed my code in last xx minutes...OK, so you've removed all your exception handlers?
    so, now I'm calling to an exe file wich should appear at a desktop or processes list... but no..
    I gave all windows rights on that file, and also through dbms_java.grant_permission..
    but, nothing happened... not exception raised, no app. started...And no output from any DBMS_OUTPUT statement? Have you tried stepping through the code in your debugger?
    Justin

Maybe you are looking for

  • SAP NetWeaver CE 7.2 Installation error in Deploying java component phase

    Dear Experts,                     I am installing CE7.2 but i am getting error in 37th phase (DEPLOY JAVA COMPONENT). Error message as An error occurred while processing option SAP NetWeaver Composition Environment (CE) 7.2 > Installation Options > A

  • Getting values from an arraylist?

    Hi there, I have the following problem. I wish to fill my txt fields with info from and arraylist right but i have the command right. I'm from Ireland and its paddys day and im stuck inside doing java all day so please help me so I can head off to th

  • After Effects Warning: A problem occurred when processing OpenGL commands

    Hi There Fellow Adobe After Effects Users. Please could some one help assist me with the following error i am getting. I bought a template and needed to do a logo animation reveal. It was done using After Effects CC for PC. AE had to then convert it

  • Safari 6.0.5 Mac won't "SAVE IMAGE AS" jpegs from web pages

    Hi. Trying to figure out what has changed here. In the past, when I've located a specific graphic on a web page - say, a .png or .jpg file through a Google image search in Safari - I could right click and choose "SAVE IMAGE AS" and download the image

  • Deployment validation failing to load DTDs for Struts

    I created a fresh webapp that includes the Struts 1.2.2 binaries and got some errors when deploying on WebLogic8.1sp3. My guess is that I need to configure some proxy setting in weblogic. Sep 7, 2004 4:07:14 PM org.apache.struts.tiles.TilesPlugin ini