Executing 2 bat files in a single java program

I have 2 bat files named batch1.bat & batch2.bat these 2 files has to run one after the other.I has written the code as bellow:
When i execute it it runs the first batch file named batch1.bat and exit. it is not running the second batch file.
can anybody please help me.
String[] command = {
                          "C:\\windows\\system32\\cmd.exe", "/y", "/c",
                          "C:\\SelfAutomate\\BestDeploy\\com\\batchfile\\batch1.bat", "C:\\SelfAutomate\\BestDeploy\\com\\batchfile\\batch2.bat"};
                 //String[] command =  new String[3];
               //command[0] = "cmd.exe";
               //command[1] = "/C";
               //command[2] = "C:\\SelfAutomate\\BestDeploy\\com\\batchfile\\batch1.bat";
               //command[3] = "cmd.exe";
               //command[3] = "C:\\SelfAutomate\\BestDeploy\\com\\batchfile\\batch2.bat";
               //command[5] =
               //command[6] = "ant";
              Process p = Runtime.getRuntime().exec(command);
              BufferedReader stdInput = new BufferedReader(new
                        InputStreamReader(p.getInputStream()));
              BufferedReader stdError = new BufferedReader(new
                        InputStreamReader(p.getErrorStream()));
              // read the output from the command
              String s = null;
              System.out.println("Here is the standard output of the command:\n");
              while ((s = stdInput.readLine()) != null) {
                   System.out.println(s);
              // read any errors from the attempted command
              System.out.println("Here is the standard error of the command (if any):\n");
              while ((s = stdError.readLine()) != null) {
                   System.out.println(s);Thanks

So what? It wouldn't run two batch files on a command shell, either. You need to call them separately. The way you do it, you just pass the name of the second batch to the first as an argument.

Similar Messages

  • Problems running bat file with calls to java programs (.jar)

    I created a bat file with calls to jar programs. In each line,
    I put a call to the programs with parameters, but bat only
    executes the first line and ends execution.
    All lines of my bat file must be executed.
    What should I do?
    Best Regards,
    Pedro Felipe
    [http://pedrofao.blogspot.com|http://pedrofao.blogspot.com]
    [http://viajantesmundo.blogspot.com/|http://viajantesmundo.blogspot.com/]

    user8730639 wrote:
    I realized that the problem isn`t my bat file. I made tests calling another jar files and then all the lines of the batch file were executed. So, the jar file called on my previous bat is finnishing the execution. I verified and the jar apps worked without error.
    I would like to know if exists any command in Java that can cause this effect (close a batch), to modify the open source code of the application.Not that I know of.
    Is prism a bat file?
    If you are invoking bat files from your bat file without using call that would explain it
    :: mymain.bat file
    :: call the first bat file
    call prism.bat arg1 arg2 arg3
    :: call the other bat file
    call prism.bat arg4 arg5 arg6
    ::

  • Hiding the command prompt when executing bat file

    Hi,
    I hava a bat file which contains following
    java -jar MyJar.jar
    When I execute the bat file, the jar file is executed. But a command prompt also opens along with it. I dont want to display the command prompt to the user. Is there any way to hide that command prompt ?
    regards,
    Jatin.

    Is your problem solved?
    If not then
    insted of creating a batch file create a form file in visual basic and write following code in it
    shell "java -jar MyJar.jar"
    Endand then create its exe file.
    It will just launch your jar file and then exit.

  • Double-click any file on desktop, calling JAVA PROGRAM

    hi guys,
    i'm breakin my head on doin this prog....when we double click a file icon of any file extension, my another
    java program should be called.
    how to do this???
    pls send a sample code........asap!!!!!!!!!
    regards,
    Sam...

    If you are using windows you could probably make a file association (for all extension types) to a batch file that in turn fires off 'java YourClass params_here'
    - but if you (can) do this, won't you screw up your desktop - ie doubleclicking on an .xls or .doc will never fire up Excel or Word, unless you change the file extension associations back to what they were before? This would make your pc kind of strange to use...??!!
    hi guys,
    i'm breakin my head on doin this
    doin this prog....when we double click a file icon of
    any file extension, my another
    java program should be called.
    how to do this???
    pls send a sample code........asap!!!!!!!!!
    regards,
    Sam...

  • How to extract .sit files(in MAC)  using java program

    Hi,
    please help me , i want to simple program for
    " how to extract .sit files(in MAC) using java program"
    that sit files same as zip files in windows..[                                                                                                                                                                                                                                                                                                                                   

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • Unable to locate existing  file from unix using java program

    Hi
    I have created a file in unix using java program, file.createNewFile();
    And when i try to search for the same file using file.exists() it is returning false. Paths are correct. Can anybody help me out.
    Thanks & Regards,
    Prasanth

    In Linux FC5 using JDK1.6, this code         File temp = new File(System.getProperty("user.home") + "/abcdefghijklmn");
            System.out.println(temp.createNewFile());prints 'true' and the file is created with length zero.

  • 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

  • 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

  • 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

  • How to execute .bat file through java?

    I already create a batch file to pull & push file. Now, i want to execute this .bat file java.I got this example but it doesnt work. Did i missed something or do we have the better one?
    import java.lang.*;
    import java.io.*;
    public class Loadfile
    public static void main(String args[]) throws IOException
    Runtime load = Runtime.getRuntime();
    r.exec("C:\\pull.bat");
    }

    For Runtime,i'd change it to:
    Runtime load = Runtime.getRuntime();
            String cmd = "C:\\javaclass\\copytemp.bat";
            Process proc = load.exec(cmd.toString());Is it right? But still can't work.
    Here is the .bat file:
    @echo off
    c:
    cd "c:\Inetpub\ftproot\Debitin"
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo open localhost
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo Administrator
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo password
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo cd ftpScript
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo binary
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd C:\
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd "C:\Inetpub\ftproot\infile"
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo prompt n
    pause
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mget *.txt::@rem >> C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mdel *.*
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo byeftp.exe -s:C:\Inetpub\ftproot\Logrecord\pullscript.txt
    ::del C:\Inetpub\ftproot\Logrecord\pullscript.txt
    pause
    exit
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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

  • Helps!:How to start multi process in a single java program?

    I wanna to test the querying performance of a Database
    connection poll,and here,not only multi threads,but also multi process I need to start in the same java program cause i have only one PC available.....
    Does that possible?

    In pure java this is not possible.
    A java program with all its thread run in a single
    jvm,
    which is just one process.However, you can have multiple instances of the jvm, I've done it w/ I needed to test some row locking in my database app. If you are in windows and want 3 copies of you program just make a bat file that looks likejavaw.exe -classpath "classesGoHere" MainClass
    javaw.exe -classpath "classesGoHere" MainClass
    javaw.exe -classpath "classesGoHere" MainClassThat will create 3 instances of the jvm and thus three instances of your application. I'm sure the same can be done on multiple platforms.
    Peter

  • How to execute .bat file within pl/sql block

    Hi,
    I want to execute a batch file (.bat) file withing a pl/sql procedure. Please guide me for it.
    Regards

    There are several possible ways to make a call-out from a PL/SQL program to the OS on the database server (but not to the client computer).
    You could use java or an external procedure (you'll need to code it in C) for example.
    You might be able to make use of UTL_HTTP to talk HTTP to another server or UTL_TCP to talk TCP to another server.
    What is it you are trying to do?

  • How to run the cmd or bat files in the con current program R12 Windows

    Hi,
    I would like to run one cmd or batch file, usually it is looking exe file only.
    How do we register the cmd or bat files?
    We encountered lot of problems to call the exe files, now we want to know to use the cmd file or batch or prog file (abc.cmd or abc.bat or abc.prog)
    Application: R12.0.4
    OS: Windows 2003
    Awaiting for your sincere response,
    Thanks,
    M.K.Thamaraiselvan

    Hi Hussien,
    Please help me that
    1. Create a file under the %FND_TOP%\bin directory called testhost.cmd
    In the file put the following two lines:
    ls >> testhost.txt
    exit
    2. From the %FND_TOP%\bin directory, do the following:
    copy fndcpesr.exe testhost.exe
    I understood the above 2 steps, the below one, is making confusion. Can you explain that what application i have to choose. 3. Register testhost (use 'testhost' for the Execution File Name) as a concurrent executable in Oracle Applications.
    4. Register a testhost host program as a concurrent program in Oracle Applications.
    5. Add the program to your report group.
    Awaiting for your explanation clearly to go ahead.
    Please explain me that which application i can choose while define the executable and program.
    awaiting.
    Thanks
    M.K.Thamaraiselvan

  • Execute bat file with cfexecute

    Hello,
    this is a newbie question but I'm stuck. I have a .bat that
    runs fine through the command prompt but won't run with
    <cfexecute>, it merely seems to read the .bat but not execute
    it. The .bat reads:
    java -classpath
    ".;C:\CFusionMX7\wwwroot\i-recall\javaClasses\GATE-3.1\bin\gate.jar"
    AnnieAPI
    When I run <cfexecute
    name="C:\CFusionMX7\wwwroot\i-recall\javaClasses\GateClasspathRun.bat"
    variable="myVar" timeout="100">
    </cfexecute>
    The output looks like this:
    C:\CFusionMX7\runtime\bin>java -classpath
    "C:\CFusionMX7\wwwroot\i-recall\javaClasses\GATE-3.1\bin\gate.jar"
    AnnieAPI
    It simply reads it and doesn't execute the java AnnieAPI
    command. I didn't write this .bat file so maybe I need to add
    something to make it run. Any help is appreciated.
    -Kalen G

    Same thing, just without the classpath in the output:
    C:\CFusionMX7\runtime\bin>java AnnieAPI
    Even if I remove the class path and simply leave java
    AnnieAPI it doesn't run. It should get an error message without the
    classpath or something but I don't And the page loads so quickly
    it's obvious that Coldfusion is just reading the code and not
    executing it.
    Thanks

Maybe you are looking for

  • "Itunes has detected an iPod that appears to be corrupted" - Ipod Classic

    I recently noticed little tiny jumps or skips appearing in songs on my 80GB ipod classic, so decided to restore it. Having done this I got the following message: "Itunes has detected an iPod that appears to be corrupted. You may need to restore this

  • TS4044 HOW DO  I GET A SCREEN SHOT, WITH MACBOOK PRO

    can you tell me how i get a screenshot with mac book pro?

  • Can't I/O select a keyword clip?

    I have a bunch of clips in an event. I have gone through these clips making selections and assigning keywords to the selections (such as "man plus car" or " happy face". In some cases I have assigned keywords to the whole clips too (such as "day 1").

  • Getting two selection screen in one report

    Hello Friends, I am Making report, In my report on first screen i have given two pushbutton, like this : SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001. PARAMETERS : p1_but RADIOBUTTON GROUP g1,                          p2_but RADIOBUTT

  • Oracle Portal

    Is Oracle Portal for Intranet Development only? Can you create a portlet and post it on your company web site for the access by external users? We want to post a form on our company web site for the access by the public to get some data in. Can this