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.

Similar Messages

  • 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();
    }

  • 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

  • How do I run an exe file from a java program?

    I need to run an exe program from within a java program.
    what do I need to do this?
    thanks

    See java.lang.Runtime.exec()

  • How do I call another exe file from a Java program?

    Hi,
    I am doing a simple IDE (text editor/interpreter) for a simple programming language we are developing. It will be submitted as our project for this semester. I created an exe file (in C) which will be used as the interpreter. How do I call the interpreter from my IDE? The interpreter should run when the user clicks a button (i.e. the "Run" button). I've tried the Java Runtime class but it doesn't work. Anyone who knows how to do it?
    Thanks!

    I first tried to do a simple program that calls system commands such as dir, cd <dir>, etc.
    I do not have the exact code right now but as far as I can remember, here's what I wrote:
    class Sample{
        public static void main(String args[]) throws IOException{
           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String command;
           while ((command = in.readLine()).equalsIgnoreCase("exit") == false){
              try{
                Runtime.getRuntime().exec(command);
              }catch(Exception e){
                 System.err.println("Error: " + e);
          System.exit(0);
    }

  • How can I EXCLUDE particular folders/files from being included in the Lightroom 5 catalog?

    How can I EXCLUDE particular folders/files from being included in the Lightroom 5 catalog?
    I want to be able to specify paths and/or filename patterns that should NEVER be indexed in the catalog: not that they don't show up under certain circumstances, just that they are NOT THERE (in the catalog) to begin with!!
    I also do NOT want to have to respecify these criteria when "synching" the catalog; criteria should be PERMANENT (or at least 'til they're changed in LR preferences).
    I cannot be the only person in the world with this problem--but it sure seems like it, because I've spent an inordinate amount of time doing online searches & I can't find anything that addresses this issue.
    Can anyone PLEASE HELP me?
    BTW, Adobe employees (if there are any of you out there), I'm simply trying out LR now.  If I can't get this (seemingly fundamental) thing worked out (with relatively little effort), Adobe is going to LOSE A SALE of LR, because it's useless to me without this feature.
    Thanks,
    -t

    Thanks for the info... but how to you TELL LR to EXCLUDE images in a particular directory/directory structure?  The intuitive place to indicate this would be a right-click on the folder itself (or particular images), but no such option exists..  "???"  Thanks again, -pt
    The same way that you avoid buying things in your local convenience store. You don't stick a lot of labels on certain shelves, slap a credit card down on the counter each week, and announce you are buying everything that doesn't have a label on its shelf. You just choose the things you want to buy.
    Your mention of "synching the catalog" suggests that you are expecting the LR library, to mirror the total images in the computer by default. This is not IMO a useful way to think about it. LR contains no images at all, by default: the Catalog starts out empty.
    Then you Add just those selected images that you want to import, among those already in the computer. That's a one-off process which is IMO best achieved controllably in batches - which you can keyword and otherwise organise in LR terms as you go. For new incoming images, ongoing, it is a question of Copying, Moving or Adding these in defined batches as they occur - from the relevant location only - there is no need to re-consider the import of a wider body of images. And one would not want to repeat that whole task anyway: one's prior investment in achieving the right selectivity, has a positive value.
    RP

  • How can I move an icon/file from one screen of my ipad to another?

    How can I move an icon/file from one screen on my ipad to another?

    Press and hold the icon until they start to wiggle. Then while holding it, drag it to the edge of the screen and wait for the page to switch, then let go of the app

  • How can  I checkout an existing file from CVS without going through the wiz

    How can I checkout an existing file from CVS, that is not already in my local jdev, without going through the wizard and checkingout everything?

    You can't. AI doesn't produce .PLT files.

  • How can I transfer a sound file from my "Voice Memos" app on my iPhone to my iPad?

    How can I transfer a sound file from my "Voice Memos" app on my iPhone to my iPad?

    In iTunes with your iPhone connected, click on the iPhone device, select the Apps tab, scroll down to the File Sharing section and pick an app that plays Quicktimes ("Files Connect" works in this example, but I'm open to suggestions of better apps for playing transferred Quicktimes) and drag your Quicktime from Finder to the Documents pane for the File Sharing app.   Once the file transfer is complete, go to the app on your iPhone to play the Quicktime.

  • How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    You can prevent it from being printed by applying a security policy to it
    in Acrobat. The rest can't be prevented, unless you spend  a LOT of money
    on DRM protection.

  • How can open a html, pdf files from the server (c:\foldername\filename)

    Hi all,
    I am developing an application. in this app i have to implement RMI.
    My problem is this, How can a client open a files from the server.
    all the html, pdf files are stored in the server's directory like C:\audit\filename.
    There is a folder on the server's C directory which contains all the html , pdf files.
    please tell me how can a client open a file from the server using RMI.
    Please send me the solution as soon as possible.
    Thanks & Regards
    Bhavishya

    That's doing it the hard way. Why not use HTTP or FTP?

  • I have converted a pdf to word. How can I access the Word file from my online account?

    I have converted a pdf to word. How can I access the Word file from my online account? When it says 'download the converted file' I choose a location on my PC and click, but nothing happens. It seems that it can only save the converted file to my online account. I went to my online account but I see no way to look for the file

    Hey Fabrizio,
    You might need to sign up at "https://cloud.acrobat.com/exportpdf" using your Adobe ID credentials to convert your PDF file to Word.
    Do you get the 'download' prompt?
    Also, you can find the converted files by clicking at the 'Files' tab. 
    Please try the same using a different browser and check.
    Hope to hear from you.
    Regards,
    Anubha

  • How can I delete two .jpg files from my desktop that refuse to be deleted?

    How can I delete two .jpg files from my desktop that refuse to be deleted?

    The two icons refused to be moved to the garbage. The good part in all this is that ater I turned off the computer at night and turned it back on the next morning they were gone!
    Thanks.

  • How can I copy all the files from my iMac to an external drive so they remain as 'regular accessible files'? I want to clean my dive

    How can I copy all the files from my iMac to an external drive so they remain as 'regular accessible files'? I want to clean my dive

    You can use a program like Carbon Copy Cloner.  It will clone your HD to the external.  The format is the same as your internal drive and you can boot from it using Option key at boot time.
    http://www.bombich.com/
    Regards,
    Captfred

  • How can I transfer all my files from Mavericks Thunderbird to Mavericks Mail

    How can I transfer all my files from Mavericks Thunderbird to Mavericks Mail?
    Bonjour,
    C'est ma première intervention aussi je ne sais pas si je peux m'exprimer en français.
    Je tente!
    Lors du passage à Maveicks, j'ai basculé sur Thunderbird car je ne souhaitais pas utiliser POP mais Mail ne le permettait pas (du moins je n'ai pas réussi)
    Aujourd'hui, je souhaite revenir sur Mail et, pour celà, je dois rapatrier toutes mes données de messagerie depuis Thunderbird.
    J'utilise Imap et, pour gérer ma messagerie, j'ai créé des boîtes aux lettres dans Local Folsders
    Le passage par Eudora ne fonctionne pas avec Mavericks.
    L'import de boîtes aux lettres depuis Local Folders de Thunderbird (via le menu Fichier) ne permet de transférer qu'un seul courier par boîte aux lettres de Local Folders. Et c'est ce qui m'empêche de passer à Mail.
    Merci d'avance pour votre aide.

    iPhone: Transferring information from your current iPhone to a new iPhone

Maybe you are looking for

  • Overriding automatic replacing of AE projects with incremental file names in Dynamic Link (CS5.5)

    Hi everyone, I've been searching all corners of the internet for an answer to this question including this forum and the Adobe help documents, so I apologize in advance if this question has been asked before. First off, we're using Premiere Pro CS5.5

  • Using 3230 as a modem--problem!

    Hi guys.. A help is needed here... I am using my 3230 as a gsm modem, to receive messages in an application in java. But the problem is that only the messages saved under "Sim messages" in the phone are available to read from 3230. So i can work arou

  • Sharp TV No Sound

    Hooked up Sharp LCD TV with HDMI cable to Charter HD cable receiver box and after 2 months suddenly no sound from TV speakers,  I can get sound with surround system.  Thought TV defective so I hooked up A/V cables Charter supplied and there is sound.

  • Helo to set locale in java

    Dear All, please help me how to set locale in java and how it works. please send me the link or code. thanks in advance Anjul Tyagi Message was edited by: Anjul Message was edited by: Anjul

  • Password aging with ACS + UCP in a wireless network.

    Hello We want to use ACS in our wireless network, but we would like to allow users to change their own passwords, so we want to use UCP. Additionally, we want to force them to change their passwords after a period of time or number of logins. Is it p