Problems with calling a Bat file in java...

i'm having some issues when i try to call my bat file within java...
here is the code
Runtime.getRuntime().exec("cmd.exe C:\\dev\\CMIC\\components\\client\\bin\\startup.bat");
it starts up the bat file but it seems to only execute the first line in the bat, then it shuts it down... i dont get it. cuz if i call that bat from another bat it works fine.. if i click on it, it works fine why would java have a problem with it?

After doing some searching around... this is what i came up with.. but i still get the same results.. the dos screen pops up and then poof.. its gone..
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
public class test {
     public static void main(String Args[]){
     System.out.println("About to try and EXecute the Bat");
               //String retVal = ExecWindows( "cmd.exe C:\\dev\\CMIC\\components\\client\\bin\\startup.bat" );
               String retVal = ExecWindows( "cmd.exe /C C:\\dev\\CMIC\\components\\client\\bin\\startup.bat" );
               System.out.println(retVal);     
     private static String ExecWindows(String cmd) {
          try {
               ByteArrayOutputStream bos = new ByteArrayOutputStream(100 * 1024);
               Runtime rt = Runtime.getRuntime();
               Process proc = rt.exec(cmd);
               StreamGobbler errorGobbler =
                    new StreamGobbler(proc.getErrorStream(), "ERROR");
               StreamGobbler outputGobbler =
                    new StreamGobbler(proc.getInputStream(), "OUTPUT", bos);
               errorGobbler.start();
               outputGobbler.start();
               int exitVal = proc.waitFor();
               //if ( DEBUG ) System.out.println( "cmd: '" + cmd + "' -> " + exitVal );
               errorGobbler.join();
               outputGobbler.join();
               //if (DEBUG && exitVal != 0)
               //     System.out.println(" ExitValue: " + exitVal);
               if (exitVal != 0)
                    return "";
               bos.flush();
               String output = bos.toString();
               bos.close();
               return output;
          } catch (Throwable t) {
               return "";
     } /* * Handle standard I/O streams */
} // end of class
     class StreamGobbler extends Thread {
          InputStream is;
          String type;
          OutputStream os;
          StreamGobbler(InputStream is, String type) {
               this(is, type, null);
          StreamGobbler(InputStream is, String type, OutputStream redirect) {
               this.is = is;
               this.type = type;
               this.os = redirect;
          public void run() {
               try {
                    PrintWriter pw = null;
                    if (os != null)
                         pw = new PrintWriter(os);
                    InputStreamReader isr = new InputStreamReader(is);
                    BufferedReader br = new BufferedReader(isr);
                    String line = null;
                    while ((line = br.readLine()) != null) {
                         //System.out.println( "{" + line + "}" );
                         if (pw != null) {
                              pw.println(line);
                         } else {
                              System.out.println(type + ">" + line);
                    if (pw != null)
                         pw.flush();
               } catch (IOException ioe) {
                    ioe.printStackTrace();
     }

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

  • Problem with opening a chm file in java.

    Hi all,
    I m having an application in which i need to open a chm file from some gui interface. I m using the following code for that...
    Process theProcess =Runtime.getRuntime().exec("hh.exe RWXml.chm");
    it is working fine on my machine. But when i deploy the code on other machine, It shows some windows error. And when i give the same command on commandline it is working fine. Can anybody tell me that what's wrong with this code.
    Thanks

    Nothing to do with ID. It really means what it says - your file permissions are hosed and it being an ID file this could include things like fonts or placed images referenced within it.
    Mylenium

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

  • Execute SSIS Package from JOB which contains Execute Process Task calling a .bat file

    Hi All,
    I have a EXCEL Macro needs to be called from SSIS. We could not use Script task because of some internal reason.
    So we have taken an approach to call a .BAT file using Execute Process Task. This .BAT file will call a .VBS file which will execute the EXCEL Macro.
    The SSIS Package is running good if I execute the package from BIDS.
    But the real problem is with the scheduling this SSIS Package using SQL JOB.
    If i execute this SSIS package from SQL Server Job, its executing the whole package successfully except the Execute Process Task.
    So the overall issue is SQL Server Job is not executing properly if I call any .BAT file from the SSIS Package.
    Please give me suggestion to get rid of the issue. Thanks in advance.

    Hi Sai.N,
    If you run the SQL Server Agent job manually from SSMS, does the package execute properly? If the package executes properly when you run the job manually, the issue should occur due to permission issue. In this case, I suggest that you create a SQL Server
    Agent proxy based on the current Windows account which you use to log onto the operating system, and run the job under the proxy account.
    If it is not the issue, please enable logging in the package as Visakh mentioned and post the warning/error message for further analysis.
    Regards,
    Mike Yin
    TechNet Community Support

  • Problem with Append mode in File Receiver

    Hello,
    I am facing some problem with Append Mode in File Receiver.
    In channel config, i have given :
    Construction Mode : Append
    File Type : Text
    Message Protocol : File Content Conversion
    The size of the file which i am trying to send is about 9.5MB.
    I got this error,
    "Recovering from loss of connection to database; message
    loaded into queue by recover job: System Job (Failover Recovery)".
    So, it would seem that there was a loss of connnection to the database    
    while the file was being written.
    Note -  XI successfully recovered from the connection loss and   
    successfully wrote the file, however since the communication channel  
    was set to append, it appended to the partial file that was written   
    before the database connection loss. This is not correct. The file    
    should have been overwritten after the recovery even though the communication
    channel was configured to append.                                     
    Can anyone help me on this regard.
    Thanks,
    Soorya.

    Hi Venkat,
    I would suggest u to split the file in to chunks if u face any problem in processing at a time in append mode and also
    Memory Requirements are must 4 processing huge files:
    Q: Which memory requirements does the File Adapter have? Is there a restriction on the maximum file size it can process?
    A: The maximum file size that can be processed by the File Adapter depends on a number of factors:
    o The most important one is the size of the Java heap, which is shared among all messages processed at a certain point in time. In order to be able to process larger messages without an out of memory error (OOM), it is recommended to increase the size of the available Java heap and/or to reduce the concurrency in the system so that fewer messages are processed in parallel.
    o Another factor negatively influencing the maximum message size in releases up to and including XI 3.0 SP 13 is an enabled charcter set (encoding) conversion if the message type is set to "Text".
    o Using the transport protocol "File Transfer Protocol (FTP)" also uses more memory for processing than the transport protocol "File System (NFS)" (up to and including XI 3.0 SP 13).
    o If the Message Protocol "File Content Conversion" is used in a File Sender channel, consider that not only the size of the input file affects the File Adapter's memory usage, but even more the size of the XML resulting from the conversion, which is usually a few factors larger than the original plain text file.
    To reduce the memory consumption in this scenario, consider configuring the setting "Maximum Recordsets per Message" for the sender channel. This will cause the input file to be split into multiple smaller mesages.
    Plz do refer the following links:
    U may plan the availability of ur communication channel using "Planning Availability Times" feature
    http://help.sap.com/saphelp_nw04/helpdata/en/45/06bd029da31122e10000000a11466f/frameset.htm
    /people/sravya.talanki2/blog/2005/11/29/night-mare-processing-huge-files-in-sap-xi
    hi check the below links for reference
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10748ef7-b2f0-2910-7cb8-c81e7f284af5
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7086f109-aaa7-2a10-0cb5-f69bd2affd2b
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2498bf90-0201-0010-4884-83568752a857
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cc1ec146-0a01-0010-90a9-b1df1d2f346f
    Regards,
    Vinod.

  • Problem with calling onApplicationStart() method

    Hi all,
         I have a problem with calling application.cfc's methods from coldfusion template. The problem is like when i am calling "onapplicationstart" method inside a cfml template i getting the error shown below
    The onApplicationStart method was not found.
    Either there are no methods with the specified method name and argument types or the onApplicationStart method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
    My code is like below.
    Application.cfc
    <cfcomponent hint="control application" output="false">
    <cfscript>
    this.name="startest";
    this.applicationtimeout = createtimespan(0,2,0,0);
    this.sessionmanagement = True;
    this.sessionTimeout = createtimespan(0,0,5,0);
    </cfscript>
    <cffunction name="onApplicationStart" returnType="boolean">
        <cfset application.myvar = "saurav">
    <cfset application.newvar ="saurav2">
        <cfreturn true>
    </cffunction>
    </cfcomponent>
    testpage.cfm
    <cfset variables.onApplicationStart()>
    I have tried to call the above method in different way also like
    1--- <cfset onApplicationStart()>
    i got error like this
    Variable ONAPPLICATIONSTART is undefined.
    2---<cfset Application.onApplicationStart()>
    The onApplicationStart method was not found.
    Either there are no methods with the specified method name and argument types or the onApplicationStart method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity
    Please help me out.
    Thanks
    Saurav

    You can't just call methods in a CFC without a reference to that CFC. This includes methods in Application.cfc.
    What are you trying to do, exactly, anyway? You'd probably be better served by placing a call to onApplicationStart within onRequestStart in Application.cfc, if your goal is to refresh the application based on some condition:
    <cffunction name="onRequestStart">
         <cfif someCondition>
              <cfset onApplicationStart()>
         </cfif>
    </cffunction>
    Dave Watts, CTO, Fig Leaf Software
    http://www.figleaf.com/
    http://training.figleaf.com/

  • Problem with RTPExport output video files

    Hi, I have a problem with RTPExport output video files. One side streams H263/RTP(AVTransmit2.java) and other write this steam to a file by RTPExport.java. When network conditions are ideal, output video file has same fps and same number of frames like original file. Problem occures, when theres packet lost in network, then output file has different fps,and also has less frames like original video(because it didnt write missing frames to file, and thats why it get shorter). Pls how can I achieve output file that will have the same fps like original one? How to write to file an identical copy of what I can see while receiveing video with AVReceive2.java? Its there a way to modifi rtpexport or avreceiver to do this? Thanks a lot!

    Trubka wrote:
    When network conditions are ideal, output video file has same fps and same number of frames like original file. Problem occures, when theres packet lost in network, then output file has different fps,and also has less frames like original video(because it didnt write missing frames to file, and thats why it get shorter). Okay, first off, the second file is smaller on purpose. RTP intentionally drops packets that are old/out of order in order to make sure real-time video stays as close to real time as it can. This is by design, so there's really nothing that can be done about it.
    How to write to file an identical copy of what I can see while receiveing video with AVReceive2.java? Technically speaking, what you're getting in the RTPExport is exactly what you got on the receiving end. Any frames that are dropped during transmission will not be seen by the receiver, nor saved by the receiver.
    Pls how can I achieve output file that will have the same fps like original one? I'm not 100% sure that you can, but, you can give the following idea a try. I make no guarentees that it'll work, but it should work for you...
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/RTPConnector.html]
    That example is an example of a "custom transport layer" for RTP connections. Essentially, it's some code that's handed the RTP packets on the transmission end, and it's expected to deliver those RTP packets on the other end. And it doesn't care about how they get from A to B, only that they do.
    If you were to replace the UDP socket in that example with a TCP socket, you would be guarenteed not to drop packets due to network reasons. Every RTP packet you were handed by the transmitter, you would then hand to the receiver. There is no guarentee that none of the packets would be cast away as "old" by the RTP protocol itself, but there's also no guarentee any of them would be. It's a crap-shoot at best, but it's certainly worth a try.

  • Running BAT file from Java

    how would i go about calling a batch file in java?
    a button is clicked that says "RUN" and then I want to run a batch file

    Hi !!!
    Im new to this forums but I think I can help you
    You can execute a separate process by using the class Runtime. In this example I execute one batch file located on the same directory the Java App is in.
    class Test
         public static void main(String a[])
              System.out.println("Executing Batch File");
              try{
              Runtime.getRuntime().exec("Runme.bat");
              catch(Exception ex){}
    }I hope that could help
    see
    how would i go about calling a batch file in java?
    a button is clicked that says "RUN" and then I want to
    run a batch file

  • .bat files and java program

    I know that I have posted something just like this before, but I just can't get this to work. I want to have my application call a .bat file and execute it. Can anyone please supply me some code (maybe just a small program) that executes a .bat file from within the program itself. This would be very helpful. I just can't get it to work at all.

    To open notepad in a windows system:
    import java.io.*; // Needed for IOException
    public class Notepad
    public static void main(String[] args)
    try
    Runtime.getRuntime().exec("notepad");
    catch (IOException ioExc)
    System.out.println("Something has gone horribly wrong!");
    Notes:
    1) notepad is usually in the path system variable. You will probably have to type in the entire path to the .bat file you want to execute.
    2) The .exec(programName) will block until the program is terminated.
    3) You are losing any semblance of system independance by doing this.

  • I need to call a batch file from java and pass arguments to that Batch file

    Hi,
    I need to call a batch file from java and pass arguments to that Batch file.
    For example say: The batch file(test.bat) contains this command: mkdir
    I need to pass the name of the directory to the batch file as an argument from My Java program.
    Runtime.getRuntime().exec("cmd /c start test.bat");
    How to pass argument to the .bat file from Java now ?
    regards,
    Krish
    Edited by: Krish4Java on Oct 17, 2007 2:47 PM

    Hi Turing,
    I am able to pass the argument directly but unable to pass as a String.
    For example:
    Runtime.getRuntime().exec("cmd /c start test.bat sample ");
    When I pass it as a value sample, I am able to receive this value sample in the batch file. Do you know how to pass a String ?
    String s1="sample";
    Runtime.getRuntime().exec("cmd /c start test.bat s1 ");
    s1 gets passed here instead of value sample to the batch file.
    Pls let me know if you have a solution.
    Thanks,
    Krish

  • Problem with Preview and PSD files - random gray square

    Hi guys, hope you can help...
    I've got a problem with Preview and PSD files.
    If I open in Preview both an original jpg straight from my reflex and the photoshop version of the same picture, the psd file presents a gray square (of what it seems unrendered image) in a random area of the photo (sometimes in the center.). The square is quite big...
    If I zoom in or zoom out it disappears...if I scroll to another photo and then back to the psd, the square it's there again...sometimes in a different position.
    I've tried the same psd on my older iMac with leopard...and got no problem at all.
    I suspect it got something to do with my Ati...
    (this is the second iMac 27...the first went back for gray banding on the lcd screen and flickering and yellow tinge........)
    Thanks for your help.
    DAve.

    maybe I'm onto something...
    I've just found out that opening Preview in 32bit mode (instead of default 64bit) works flawlessly with any psd files. If I switch back to 64bit mode, Preview is much faster but the gray square comes back...
    It seems like the i7 is much faster than the Ati....
    Any more realistic ideas?

  • Problem with calling on some numbers

    Hi my mum has problem with calling on my number. She is in the USA and has a lof of money on her Skype account. When she was in Poland (country when I am now) she could without any troubles calling on my number. What is wird now in the USA she can call on some other polish numbers (I think that Skype doesn't support connection with my mobile operator).
    I fell deceived because I created Skype account and transfered some money on it for my mum to give her possibility to call to me. Is possible to fix it? Is somewhere table with can help me check which one numbers (mobile operators) Skype supports in the USA?
    My mom used Skype from Android smartphone.

    Hi my mum has problem with calling on my number. She is in the USA and has a lof of money on her Skype account. When she was in Poland (country when I am now) she could without any troubles calling on my number. What is wird now in the USA she can call on some other polish numbers (I think that Skype doesn't support connection with my mobile operator).
    I fell deceived because I created Skype account and transfered some money on it for my mum to give her possibility to call to me. Is possible to fix it? Is somewhere table with can help me check which one numbers (mobile operators) Skype supports in the USA?
    My mom used Skype from Android smartphone.

  • I have problems with seeing my bookmarks, file, view, edit...buttons. I tried other shortcuts. I noticed that all of my bookmarks are located in the Internet Explorer browsers, how can I restore setting back to Mozilla Firefox?

    I have problems with seeing my bookmarks, file, view, edit...buttons. I tried other shortcuts. I noticed that all of my bookmarks are located in the Internet Explorer browsers, how can I restore setting back to Mozilla Firefox?

    Is the menu bar missing (the one containing File, View, Edit etc)? If it is, the following link shows how to restore it - https://support.mozilla.com/kb/Menu+bar+is+missing

  • I have a problem with running an EXE file on win2000, the Lab View is 5.1 and I do not know if it is 16 bit...

    I have a problem with running an EXE file on win2000, the Lab View is 5.1 and I do not know if it is 16 bit...what should I do?

    Hi Arika,
    The drivers that you need to install to make your executable work depends on what your executable is doing. To get started, you need to have the LabVIEW Run-Time Engine installed on your target machine (the Win2000 machine you are planning to use) in order to run your executable. Next, you need to determine what drivers your executable uses, if any. For example, if you are using GPIB instrument control, you will need to install the NI-488 drivers on your target machine. If you are performing data acquisition, you will need to install NI-DAQ drivers. If you are doing image acquistion, you will need to install NI-IMAQ drivers.
    All these drivers are available for downloading on ni.com. To get the drivers, go to ht
    tp://www.ni.com/support , click on the link that takes you to Drivers and Updates (under Option 3), and click on the links to get to the driver(s) you need. For example, if you need the LabVIEW 5.1.1 Run-Time engine, click on the All Drivers and Updates by Application link on the main page (http://www.ni.com/softlib.nsf/). Then click on the LabVIEW link, Windows 2000, Run Time Engine, and then you will see the link to get to the page to download the LabVIEW 5.1.1 Run-Time Engine.
    I hope this information helps.
    Best Regards,
    Wilbur Shen
    National Instruments

Maybe you are looking for

  • What needs to be configured on a webstart client pc

    Hi there, Here is my problem: I have a J2SE application which is being deployed with WebStart. Everthing works fine for me and most of the users: They click on a link to the JNLP-File, their Internet Explorer pops up and immediately Java WebStart sta

  • Video does not play using windows XP running on MAC BOOK PRO?

    noticed this problem with someone i know using a 15 MBP somehow it does not play videos using windows xp?

  • How to Install ZENworks Adaptive Agent on Macintosh

    This might sound ridiculous, but I am really new at Macintosh and cannot get the Agent to install. To be upfront, my ZCM is currently at version 11.2.0 and I realize it probably won't work on my new 10.9.1 Macintosh Maverick computer. Nevertheless, w

  • ORABPEL-10516 - Beehive Custom Workflow Tutorial

    Hi all, I am (still) trying to set up the Beehive custom workflow tutorial. The BPEL process fails: Faulted while invoking operation "initiateTask" on provider "TaskService" ORABPEL-10516 Identity Service cannot find user. Error occurs while getting

  • OCI vs OO4O vs Oracle OLEDB vs MS Oracle OLEDB

    I'm developing an application that needs to get database schema information (Tables, Columns, Stored Procedures, Views, etc.) as well as execute SQL statements against an Oracle database. From a developer's perspective, is their an advantage of using