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

Similar Messages

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

  • Iam not able to share internet in windows 8 from my macbook air...though my iphone ipad is connected to the hotspot well..tried everything but it seems to be different from windows 7  and other microsft operating systems setting. help!!

    Iam not able to share internet in windows 8 from my macbook air...though my iphone ipad is connected to the hotspot well..tried everything but it seems to be different from windows 7  and other microsft operating systems setting. help!!

    Ask on a Windows forum since that's what you're having a problem with.

  • How to run a batch file from within an Oracle 9i Form?

    Hi, I would like to execute a batch file from within an oracle form - I'm assuming there's some PLSQL command I can use? I am not allowed to use any third party libraries, and I'm hoping I can get away without having to progam any C or Java to do it. I don't want to run my java program from my form, but my lecturer is insisting on it.
    Can anyone help?
    Thanx
    Adam

    Can u give me an example
    I need to run a batch files that does a series of step doing dir ( in 3 different folders)
    after each one it shows on screen with a pause & user press enter
    can this work out ?

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • I'm not able to run a simple Hello Program in java

    I have just now installed jdk 1.3.1_2.
    I have set the path and class path.
    I'm able to compile the class without any errors but am not able to run the program.
    when i say java Hello(after compiling Hello.java), i'm seeing the following error:
    Exception in thread "main" java.lang.NoclassDefFoundError:Hello
    Thanks in advance in this regard

    Hmm..
    Okay.. set aside any import or package stuffs.. lets say about a simple HelloWorld program which is called Hello.class. It resides in c:\, which means the full path is c:\Hello.class.
    Make sure you got one of your path as c:\jdk1.3\bin(assuming you are using jdk 1.3).
    If you are in the same directory as Hello.class, which is c:\>, you can execute the class file by typing:
    C:\>java Hello
    If you are not in the same directory and you wishes to run the class file, example you are in directory temp now:
    C:\Temp>java -cp C:\ Hello
    So the cp set will be just c:\. Hope that answers your question somehow.. well... if I never intepret it wrongly.

  • Not able to run a simple RMI server

    I am running an RMI program like follwing
    import java.rmi.* ;
    import java.rmi.registry.* ;
    import java.rmi.server.* ;
    public class CallBeanServer extends UnicastRemoteObject implements ICallBeanServer
         //main
         public static void main(String args[]) throws Exception
              int port = 1000 ;
              Registry reg = null ;
              if( args[0].equals("true"))
                   reg = LocateRegistry.createRegistry(port) ;
                   System.out.println("Successfully created registry") ;
              else
                   reg = LocateRegistry.getRegistry(port) ;
                   System.out.println("Connected to existing registry") ;
              CallBeanServer callBeanServer = new CallBeanServer(reg) ;
         }//main
         //constructor
         public CallBeanServer(Registry reg) throws Exception, RemoteException
              super() ;
              reg.rebind("CallBeanServer",this) ;
              System.out.println("CallBeanServer Object bound") ;
         //my public method
         public String callBeanServer() throws RemoteException
         {          return "Success" ;
    I have run the rmiregistry at port no 1000 like
    rmiregistry 1000
    I have compiled ICallBeanServer also and run rmic also over CallBeanServer like
    rmic CallBeanServer
    when I run this program using
    java CallBeanServer false
    it gives the follwoing errors
    Connected to existing registry
    Exception in thread "main" java.rmi.ServerException: Server RemoteException; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    java.lang.ClassNotFoundException: CallBeanServer_Stub
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at CallBeanServer.<init>(CallBeanServer.java:38)
    at CallBeanServer.main(CallBeanServer.java:30)
    Can you please tell me what is the error?
    Thanks
    Prashant Gupta

    Add the classes (the stubs included) to the classpath when you start the registry.

  • Nikon D800 raw files taken with Sandisk extreme plus 32GB SDHC card got corrupted. Able to preview them in Lightroom4.4 Library, but not able to import or transfer the files from card to computer. Any ideas on how to save images from Library Window in Lig

    Hi, I have shot few pictures on 31st December night in RAW mode using Nikon D800 and Sandisk extreme plus 32GB SDHC card. It looks like card got some memory errors so not able to transfer the files from Card to computer. However I am able to view the pics thru Lightroom ver 4.4 Library, but when I tried to import them, it gives me an error stating that file can't be read.
    Is there a way to save the pics from Library window in lightroom overcoming the card read errors ?
    Thanks in advance

    Hi SSPRENGEL,
    Thank you for your response. Here is the error message I am receiving, I tried with various destination folders in the computer but it still gives the same error:. Just to let you know, I am able to import pictures into these folders from other memory cards.
    I am able to finally at least extract the jpgs using the option suggested by elie-d

  • NOT ABLE TO IMPORT MUSIC AND VIDEO FILES FROM IPOD TO COMPUTER/ITUNES LIBRARY !!!!

    Hi.... I am having IPod Nano 5th Generation. I can access music and video files (that are stored in Ipod memory) in Ipod. But when I connect the ipod to computer, I am not able to access/import these music and video files through computer. Also, I am not able to see any folders like DCIM, Contacts, etc... in the memory of IPod. Can any body help me out... ?

    Search it up on google.com.  There's a lot of apps that will help you do this.  Check out this one:
    http://www.imtoo.com/ipod-computer-transfer.html
    You can also check out this video:
    http://www.youtube.com/watch?v=dWvYo6Gcq44
    I tried the import software (trial version) and it was fine but I didn't want to pay for software.  You can authorize up to 5 computers in the house to access your iTunes music and other iTunes purchases. Open iTunes, you can go under Store and select Authoize this computer.
    Good luck!

  • Not able to open the existing PDF files from Content Server in VL02N

    Hi All,
    In Delivery transaction VL02N, we are not able to open the PDF file attachments which were created in the Past (Ex. 01/01/2014) from the Content Server. Recently upgraded to Enhancement Pack 7 and not sure whether the issue is due to this upgrade.
    Kindly check and do the needful.
    Thanks,
    Parasuram

    Hello,
    What error or information did you met?
    Are there any information in transaction SLG1?
    Regards,
    David

  • How to invoke the .bat(batch file ) from the java program

    i want to run some commands when i run one java program.
    I wrote those dos commands on the batch file and i want to include the bat file in the java program so that i can execute the bat file when i run the java program.
    tell me the way that i can run my bat file inside the java program.

    i tried this :
    a .bat file named test.bat, with this code : copy test.bat test2.bat
    a java class, Test.class, in the same directory
    public class Test {
         public static void main(String[] args) {
              try {           
                   Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec("cmd /c test.bat");
                   proc.waitFor();
                   int exitVal = proc.exitValue();
                   System.out.println("Process exitValue: " + exitVal);
              catch (Throwable t) {
                   t.printStackTrace();
    }

  • Run remote batch file from Web Application Server

    Hello,
    I've developyed a Java program and deployed it on WAS v7.1.
    My java program tries to run a remote batch file which is located on remote Windows file system (and not on the WAS file system itself).
    The batch file was launched on the remote server (I saw it on the Task Manager of the remote server), but the remote batch file actually wasn't run (it was stuck).
    In order to run the remote batch file from my java program that is deployed on the WAS I've created a batch file on the WAS file system which its contnet is:
    cd c:\jobs
    psexec.exe 
    iltlvt40 -u SAPServiceCE1 -p a2i2000! c:\automation\DiskSpace\runDiskSpace.bat
    The jobs folder contains the psexec.exe file (you can find more details about the psexec on this link: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx).
    iltlvt40 is the remote server.
    SAPServiceCE1/a2i2000! is a user/password on the remote server which has a full permissions.
    My java program calls this batch file using the Runtime.exec() java method in order to run the remote batch file.
    Please guide me how to solve this problem?
    Best regards,
    Ahmad

    Hi,
    To which batch file you have meant to add some commands: for the local one or remote?
    I've added to the local one some different commands and it's works.
    I think there is a permission problem when we are trying to go out of the WAS file system.
    Best regards,
    Ahmad

  • URGENT:- Running a batch file from java program

    Author: pkanury
    I am trying to execute a batch file from my java program using RunTime and Process . It can execute any dos command except for a batch file. Can anyone throw
    some light ?? My code looks like this .....
    cmd = "command.com /c X:\\grits\\scripts\\test.bat"; Runtime rt = Runtime.getRuntime(); Process p = rt.exec(cmd);
    The weird part is that p.waitFor() returns a status of 0 implying that the cmd has been executed successfully. But that is not the case. And my batch file is as simple as - type "ADADA" > junk.txt
    Any help would be appreciated.

    I think it should work when you use a String[] array
    instead of a single String:
    String[] cmd = { "command.com", "/C", "D:\\batch\\do.bat" };
    Note: If the batchfile creates any output (i.e. files),
    they will be stored in the directory of the application
    which calls the batch file, not in d:\batch\...

  • Error running batch files from java source file???

    Dear Friends,
    hi,
    this is with response to a doubt i had earlier ,
    i want to run batch files from the java source file ,i tried using this code (here batrun is the batch file name that contains commands to run other java files)
    try
    String [] command = {"c:\\vishal\\finalmain\\batrun"};
    Runtime.getRuntime().exec(command);
    catch(Exception e)
    but i got the following error.
    java.io.IOException: CreateProcess: gnagarrun error= 2
    plz. help me, i tried all combination w/o success,
    in anticipation(if possible give the code after testing)
    Vishal.

    hello there,
    i solved the prob. by using
    cmd /c start filename ,but i need to pass parameters ie
    cmd /c start java "c:/vishal/runfile a b" where a and b are the parameters. but it is not accepting this in Runtime.getRuntime.exec(),
    any solutions ?????????
    regards,
    Vishal

  • Running batch files  from Java using exec method

    Hi,
    I want to run a batch file from my Java program like this:
    try {
    Process proc = Runtime.getRuntime().exec("C:\\Refresh.bat");
    catch (Exception e) {
    MessageBox.show(e.getMessage());
    Refresh.bat file contains two commands.
    First one unzips certain zip file.
    Second one refreshes a SQL Server database using osql utility.
    Problem is that when program is run it executes only the first command and hangs on the second one.
    Please help.
    TIA
    Ravinder

    From the FAQ:
    2. How do you launch an external program on a Microsoft Windows platform from a program developed on the Java [tm] programming language?
    The following will launch notepad in Microsoft Windows NT:
    Runtime.getRuntime().exec("cmd /c notepad.exe");
    To launch a program in Microsoft Windows 95/98 use:
    Runtime.getRuntime().exec("c:\\windows\\notepad.exe");
    The Runtime class allows interaction between a program and its environment. The first string command instructs the command line interpretor, cmd to open up the calculator application.
    The exec() methods do not use a shell; any arguments must have the full pathname to the shell as well as the command itself.
    For example, to run a shell on the UNIX� platform, type:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("/usr/bin/sh -c date");
    To run a batch file under Microsoft Windows 95/98:
    Process p = rt.exec("command.com /c c:\\mydir\\myfile.bat");
    To run a batch file under Microsoft Windows NT:
    Process p = rt.exec("cmd /c c:\\mydir\\myfile.bat");
    where 'cmd' and 'command.com' are the command-line interpreters for Microsoft Windows machines.
    The Runtime.exec() methods might not work effectively for some processes on certain platforms. Special care should be taken with native windowing, daemon, WIN16/DOS process or some shell scripts.
    regards,
    jarshe

Maybe you are looking for

  • No Standalone Upgrade Pathway For CS6 Apps

    As many of you who are regular in the forums know, I am a supporter and early adopter of Creative Cloud. However as few you are ready to admit, I'm not a blind sheep drinking the red Adobe Koolaid... There are in fact glaring flaws in Adobe Creative

  • Connecting HD TV to Home Wireless Network

    I recently purchased Apple TV as a means to wirelessly connect to my HD TV. I was greatly disappointed by the restrictions placed on the device and returned it to Apple at the cost of a restocking fee. You could view I-tunes and I-photo content but t

  • How do I load prepaid airtime on ipad mini if it doesn't support SMS?

    Please don't tell me to buy a adaptor so that the nano sim fits in iPhone and all that crap! In the middle of the ocean it's impossible to buy anything.

  • Domain name and iweb - masking url?

    i have a domain name and want to use it for my website i created on iweb - is there a way to mask the url so when people type in my domain name they are directed to my iweb site?? thanks

  • Load Default Value after CreateInsert.Execute

    Hello all ! this is my first post so be polite ;) Well i have this input that is binding to a DataControl <af:inputText value="#{bindings.ApiState.label}"                                       label="#{bindings.ApiState.inputValue}"