Runtime.exec(bat file) : doesn't display stdio

Hello, I need to start bat files from my Java Application
to do this, I use
Runtime.getRuntime().exec("my_bat.bat");
a Dos console is opened.
if my_bat.bat
starts notepad.exe ==> it works
if my_bat.bat
does echo hello world ==> nothing is displayed.
I would like the STDOUT procuded by the .bat file to be
displayed in the console.
Anyone can help me?
Regards.

You need to get the input stream from the process, and print out what it sends. Simply calling "waitFor()" will wait forever, since the stdout characters need to be read.
Try this :
InputStream st = Runtime.getRuntime().exec("hello_world.bat").getInputStream();
int n;
while ((n = st.read()) >= 0) {
  System.out((char)n);
}Walter Gildersleeve
Productivity Engineering, GmbH
Freiburg, Germany

Similar Messages

  • Runtime.exec() batch file problem

    Hi folks,
    i have a little problem when I want to execute a batch file through java's runtime.exec() method.
    the execution of a very simple batchfile works (for example opening notepad or other stuff), but I have problems with the following batch file (although it's still simple):
    net use s: \\Dd-nt-fs\Dsmp15_files
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    set path=S:\Dsmp_Q4_2004\Bin;%ora_path%\bin;%path%;
    set nd_font=S:\Dsmp_Q4_2004\Fonts
    set nxPS_FONT_DIR=%ND_FONT%
    set PSPATH=c:\adproof
    set PSFORMS=S:\Dsmp_Q4_2004\PsForms\Telenor
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    my guess is that there is a problem with the setting of environment variables which correspond to the drive s:
    I mannually added the batchfile (line by line) and looked whether it got through to the command which executes the adproof.exe file: for example the below batchfile worked:
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    Here is the java code: in which i execute the batch file:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("net use s: \\\\Dd-nt-fs\\DSMP15_FILES");
    BufferedReader  b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
          System.out.println(line);
    int exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);
    String[] cmd = new String[1];
    cmd[0] = "C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print\\hallo3.bat";
    // here i declared the needed settings of the environment variable and pass that array to the exec() method                   
    String[] env = new String[8];
    env[0] = "DSCFG=c:\\dscfg";
    env[1] = "ORA_PATH=C:\\oracle\\ora92";
    env[2] = "PSPATH=C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print";
    env[3] = "ND_FONT=S:\\Dsmp_Q4_2004\\Fonts";
    env[4] = "nxPS_FONT_DIR=%ND_FONT%";
    env[5] = "PSFORMS=S:\\Dsmp_Q4_2004\\PsForms\\Telenor";
    env[6] = "ND_PATH=S:\\Dsmp_Q4_2004\\resource";
    env[7] = "PATH=S:\\Dsmp_Q4_2004\\Bin;%ORA_PATH%\\BIN;%ND_PATH%;%PATH%;";
    rt  = Runtime.getRuntime();
    proc = rt.exec(cmd, env);
    b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
              System.out.println(line);
    exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);Maybe someone else had similar problems or can help me solving that problem.
    Any advice would be very appreciated.
    regards
    mirkolino

    finally I got it working now.
    for those who are interested in the problem, my code that's now working is the following
    Runtime rt = Runtime.getRuntime();
                            Process proc = null;
                            String cmd = "cmd.exe /c c:\\adproof\\hallo3.bat";
                            proc = rt.exec(cmd);
                            InputStream in = proc.getInputStream();
                            BufferedReader br = new BufferedReader ( new InputStreamReader(in));
                            String line;
                            while( (line=br.readLine()) != null) {
                                System.out.println(line);
                            int exit = proc.waitFor();
                            System.out.println();
                            System.out.println("Process exited with: " + exit);the problem was, that i have to handle and read the input stream
    thanks for you help
    greetings from mirkolino

  • How to capture Runtime.exec() output? doesn't seem to work?

    This is the first time I've used Runtime.exec();
    Here's the code:
    Runtime rt = Runtime.getRuntime();
                process = rt.exec(jobCommand);
                BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line=null;
                while((line=input.readLine()) != null) {
                     System.out.println("OUTPUT: " + line);
                int exitVal = process.waitFor();
            } catch(Exception e) {
                 e.printStackTrace();
            }//end catchas you can see, this is just copied and pasted out of the standard example for this method.
    When it gets to the line:
    while((line=input.readLine()) != null)
    it doesn't read anything. However, when i run the SAME exact command from the windows CMD prompt i get a ton of output.
    what am i doing wrong here?
    thanks.

    Welcome to the forum!
    >
    as you can see, this is just copied and pasted out of the standard example for this method.
    >
    No one can see that - you didn't post a link to the example you said you copied.
    >
    it doesn't read anything. However, when i run the SAME exact command from the windows CMD prompt i get a ton of output.
    >
    No one can see what command you are talking about; you didn't post the commnd or even describe what output you expect to get.
    >
    what am i doing wrong here?
    >
    What you are doing wrong is not providing the code you are using, the command you are using or enough information about what exactly you are doing.
    No one can try to reproduce your problem based on what you posted.

  • Runtime.exec - hangs or doesn't produce output

    Hey,
    I've been trying to get my program to run an application that I downloaded off the net. It is a console based telnet application build for windows. Now, I've been trying to bascially automate some telnet stuff but it doesn't seem to work at the moment that is it doesn't give me output and it causes my computer to slow down. I've noticed that it does start the application which causes the slow down but I was wondering why it doesn't give me any output. Here is the code that I have
    import java.io.*;
    public class Main
      public static void main(String[] args)
        String command = new String[3];
        command[0] = "cmd.exe";
        command[1] = "/C";
        command[2] = "D:\\Temp\\telnet\telnet.exe";
        try
          Process p = Runtime.getRuntime().exec(command);
          BufferdReader stdin = new BufferedReader(new InputStreamReader
                                                   (p.getInputStream()));
          BufferedReader stderr = new BufferedRader(new InputStreamReader
                                                   (p.getErrorStream()));
          PrintStream stdout = new PrintStream(p.getOutputStream());
          String line = "";
          while((line = stderr.readLine()) != null)
            System.out.println(line);
          System.out.println();
          while((line = stdin.readLine()) != null)
            System.out.println(line);
          p.destroy();
        catch(Exception ex)
          System.out.println("Exception: " + ex.getMessage());
          System.exit(-1);
    }Could some please help me and trying to get this program to work?
    Thanks,
    Ny

    now try it
    you should get
    D:\Temp\telnet' is not recognized as an internal or external command,
    operable program or batch file.
    as an output
    import java.io.*;
    public class Main{
      public static void main(String[] args)
        String[] command = new String[3];
        command[0] = "cmd.exe";
        command[1] = "/C";
        command[2] = "D:\\Temp\\telnet\telnet.exe";
        try
          Process p = Runtime.getRuntime().exec(command);
          BufferedReader stdin = new BufferedReader(new InputStreamReader
                                                   (p.getInputStream()));
          BufferedReader stderr = new BufferedReader(new InputStreamReader
                                                   (p.getErrorStream()));
          PrintStream stdout = new PrintStream(p.getOutputStream());
          String line = "";
          while((line = stderr.readLine()) != null)
            System.out.println(line);
          System.out.println();
          while((line = stdin.readLine()) != null)
            System.out.println(line);
          p.destroy();
        catch(Exception ex)
          System.out.println("Exception: " + ex.getMessage());
          System.exit(-1);
    }

  • PDF file doesn't display properly unless Firefox is maximized.

    When I try to view a PDF file in Firefox, the page is too light to read unless the Firefox is maximized. Try http://www.sgsd.k12.wi.us/foodservice/Shawano%20Food%20Service%20Web%20Site/Documents/Menus/September/Lunch%201.pdf
    click on the "Restore down" button and see if you can read it. It displays fine when maximized, so it's a nuisance rather than a big problem. Just curious if any one else noticed.

    Old Toad:
    I finally got it! the favicon works now at: http://web.me.com/phelpssculpture
    Your Instructions at:http://toadstutorials.info/ #22 did the trick.
    One problem I had with TextWrangle was I was doing a search and replace for <head><meta and it wasn't working. What I figured out was that there was other code on the line after <head><meta which was preventing the new code from working. I did a minor adjustment on each page in iWeb to force it to republish each page. That made the <head><meta line consistent on each page, then I selected the entire line and replaced it as per your instructions. It worked great. My experience was that iTweak did not process the code properly and was very slow, but this process was great.
    Thank you for all your help. Sincerely, David

  • SSRS - MHTML File Doesn't Display Charts/Graphs

    Hi,
    I'm trying to export a SSRS report to MHTML, but the included graphs is not displayed. Why?
    Can you please explain to me how to fix this issue?
    Regards,
    Bader

    Hi Bader,
    From your description, the Charts/Graphics included in the report are not displayed when viewing the exported MHTML file. From the "Export the report" section of the article
    View a Reporting Services report, I suggest that you export the report to MHTML again, and then check the issue.
    If the issue persists, the charts/graphics might be blocked by certain Internet Explorer settings. In this condition, I suggest that you open the MHTML file through a third party browser. Meanwhile, you can check the IE Advanced settings. For example,
    please check the following options are enabled:
    Enable automatic image resizing
    Allow active content to run in files on My Computer*
    Hope this helps.
    Regards,
    Mike Yin
    TechNet Subscriber Support
    If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback
    here.
    Mike Yin
    TechNet Community Support

  • Swf File doesn't display in chrome but displays in firefox

    Hi there, I made a swf file and embed it in my website.
    URL: http://worldwidefilipinoalliance.com
    It displays properly in the mozilla firefox but not in my google chrome.
    Is this problem related to the browser or the way that I embeded my swf file.
    Can you give me a tip on how to solve this.
    Thank you and regards!

    Your embedding code appears to be minimal, as well as the old version, which could be the problem.  The more modern embedding code will use either swfobject or other javascript-based coding.  If you can get a hold of a newer version of Flash you should let Flash generate an html page and then copy and paste the embedding code from that into your html page.

  • New import from imoviehd6 file doesn't display in preview while skimming

    All i get is plain box. I have imported several hour of footage so far without any problems. I have seen others have different preview issues or it might be related. Any ideas on how to troubleshoot? This is my first real issue with imovie. I was holding breath until now. Nothing has changed on my system other than i downloaded JES video cleaner.
    I also want to add that if if drag footage to a project i can then see the footage.
    Message was edited by: Sheryl Kingstone

    Hello, Sheryl,
    Yes, iMovie 9 is supposed to save everything you do because it is designed to keep all the originals intact and just create references to your changes/edits. And, it is supposed to remember and 'save' all your edits to your project when you close it. However, if you have a crash or one of those 'iMovie has unexpectedly quit' episodes, all your edits from after the last save are lost. Another reason to like iMovie 6--you can save your movie whenever you want. Some people have experience loss of edits in iM 8/9 even if doing everything correctly; no crashes, but the new edits were not there when iMovie was reopened. I havent used it so I cannot speak from experience....just from reading here.
    And, I have been following your posts with Steve Mullen's re: quality of videos--what settings, interlacing, etc. It is very informative....I don't have to ask anything because you posted either my questions or answers to them!

  • Flash content doesn't display in browsers

    I recently updated Dreamweaver to 8.0.2. I updated an .swf
    file, updated the link on my DreamWeaver page and uploaded
    everything. When I saved the DreamWeaver page a window popped up
    that said it was modifying the html to work with the updated
    Internet Explorer. The new .swf file doesn't display on any browers
    (Safari, FireFox, IE)
    Does anyone know what's going on?

    Did you upload the Scripts folder that DW places into your
    local site when
    you do this?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "dlipscombe" <[email protected]> wrote in
    message
    news:ecv25g$i9v$[email protected]..
    >I recently updated Dreamweaver to 8.0.2. I updated an
    .swf file, updated
    >the
    > link on my DreamWeaver page and uploaded everything.
    When I saved the
    > DreamWeaver page a window popped up that said it was
    modifying the html to
    > work
    > with the updated Internet Explorer. The new .swf file
    doesn't display on
    > any
    > browers (Safari, FireFox, IE)
    > Does anyone know what's going on?
    >

  • Flash CS5.5, SWF file doesn't load TLF text.

    Hiya,
    I just downloaded the trial version of Flash 5.5. I was trying to a tutorial from  Adobe Classroom in a Book: Flash Professional CS5. I was trying to do lesson 7 which is all about TLF text.
    In the tutorial, you insert text that is TLF text. Most of the text doesn't do anything (it's Read-Only). But there is one area that is supposed to be a Mortgage Calcualtor and functions with ActionScript.
    I inserted the ActionScript that makes the Mortgage Calculator text do the proper math. My problem happens when I try to test the movie: the SWF file doesn't display any of the TLF text, and the Output panel gives me the following:
    ReferenceError: Error #1065: Variable TLFTextField is not defined.
    ReferenceError: Error #1065: Variable TCMText is not defined.
    I am confused because there aren't any variables with those names in any of the files of the tutorial, or in the ActionScript I entered. Where is Flash getting those variable names from? O_o
    I even turned the text back into Classic text to see if that helped, but I still get the error. Could this be a glitch with Flash 5.5?
    Thanks for your time.
    Tara

    That file has all the menu items in it.
    A crossdomain file is use as a security measure. Perhaps I see it because I use a webpage on my own server to display your SWF file. Check to see if that's the case with you.
    But I gave it another try.
    I downloaded the menu.swf and the xml file and stored them in a folder. I use a custom webpage and stored that in the same folder.
    Instead of the full URL is simply use the filename.
    <object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/ flash/swflash.cab#version=6,0,40,0" border="0"
    width="870" height="800">
    <param name="movie" value="menu.swf">
    <param name="quality" value="High">
    <embed src="menu.swf"
    pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1"
    width="870" height="150"></object>
    That works.
    When I paste the <object> code in the HTML Snippet and use relative URLs to the menu in the folder mentioned above, I noticed that the XMLHorizontalMenu.xml is expected to be in the Pagename_files folder. That folder belongs to the iWeb pages it is embedded in. When I put the xml file there, the menu works.
    You have to check the design of the menu.swf file.
    Otherwise, store all files in a separate folder and use a <iframe> to embed it.

  • Performance issue Runtime. exec("cp folder1 folder") in Linux,Weblogic.

    Using Runtime. exec() copying files from folder1 to folder2 using cp command in Linux. It will take each file copy 2 sec if we use web logic 10.3 and jrocket. if we run in Linux without web logic it takes only 0.013 sec. why it takes more time to load cp command with web logic.
    Environment
    Weblogic 10.3
    Linux 5.2
    Jrocket 1.6

    A 64 bit VM is not necessarily faster than a 32 bit one. I remember at least on suggestion that it could be slower.
    Make sure you use the -server option.
    As a guess IBM isn't necessarily a slouch when it comes to Java. It might simply be that their VM was faster. Could have used a different dom library as well.
    Could be an environment problem of course.
    Profiling the application and the machine as well might provide information.

  • Runtime.exec() with .bat-files in a jar

    Hi All,
    I've written a java-Program, which calls .bat-files per Runtime.exec() for some OS-specific tasks.
    Everything works fine, but if I want to pack the whole code and the .bat-files into several jars, I can't get the bat-files to run. I have tried to get it to work with "getClass().getResource()" as I do the same for my Images, and the returned URL seems to be OK so far (something like jar:file:/c:/test.jar! testpkg/test.bat). I converted this URL into a String and tried to run Runtime.exec() with it, but I always get a Runtime-Exception.
    The String looks exactly like the URL, when I print them to console.
    These bat-files are essential for the application and I would not try to pack them into a jar if I hadn't to distribute this application as a signed applet to unknown users, too.
    I hope there is anyone out there who can tell me if and how it is possible to run an external program out of java, which is packed into a jar, so thanx in advance to any helpful replies.
    acdeka

    You can't run the .bats simply because the shell can't access it. You tell it to run a file that simply doesn't exist in the OS.

  • Executing bat file without using Runtime.exec()??

    Hi all
    From my java App ,I am running a bat file. This is what I did:
    When I press 'execute' button inside my App, it runs a bat file through Runtime.exec() method. Since exec() runs it through cmd.exe, get a DOS window when I press Execute button. If I manually runs my app from command promt , I dont get it. But I have to create a short cut of my main class in the desktop. This is happening when I run my app from desktop icon.
    Now I want to eleminate DOS popup everytime I press execute button. Would anyone pls give an idea how to run bat file without using Runtime.exec()? Any suggestion will be helpful.
    Thanks

    jscell
    Thanks for taking time to answer to my problem .
    Here is what my problem: I create a shortcut of my main class in the desktop. Through this shortcut ,I run my java App. My App has a execute button, When I press this button , It run another bat file through Runtime.exec() method, and show some result in the result PAnel. NOw what happen , I get a DOS command window , everytime I press execute button. , Which is very annoying . But If I run my App thorugh command promt by executing: "java myApp", then I dont get this DOS popup. But I have to create a shortcut in the desktop, so other can use it conveniently.
    NOw I am not sure why I am getting this DOS window in the middle of my Application. IS it for using Runtime.exec() method? or for running bat file through my application? Can anyone pls tell me? I am kind of new to java, and I am learning lot of stuff from this forum .
    Would u pls suggest me about how to eleminate this DOS popup when I press execute button.
    Regrds

  • Problem of using Runtime.exec() to run .bat

    hi,
    i try to rum a .bat in the following way:
    Runtime runtime = Runtime.getRuntime();
    Process proc=runtime.exec("cmd.exe /c c:/test.bat");
    int exitVal=proc.waitFor();
    System.out.println("exitVal: "+exitVal);
    but it doesn' t work...
    ,and i get a exit value '1'
    what dose it mean?

    hi,
    i try to rum a .bat in the following way:
    Runtime runtime = Runtime.getRuntime();
    Process proc=runtime.exec("cmd.exe /c c:/test.bat");if it is already a .bat file, why do you invoke it with cmd.exe?? try running it directly as
    Process proc=runtime.exec("c:/test.bat");

  • Opening FTP connection using a bat file by Runtime class

    Hi
    I'm trying to run the following file from Runtime.getRuntime().exec(XXX) command and getting an error saying that login failed.
    I have set the user id and password in the ftpcommand.bat file as below
    User nkamar
    pass narendra
    and when I run this bat file from command prompt it doesn't work why???.It says Login failed.
    C:\>ftp -s:ftpcommand.bat 134.133.210.24
    Connected to 134.133.210.24.
    220 sdqa33 FTP server (SunOS 5.6) ready.
    User (134.133.210.24:(none)):
    331 Password required for User nkamar.
    530 Login incorrect.
    Login failed.
    ftp> opsnet1
    Invalid command.
    ftp> Invalid command.
    can you please help me in resolving this.
    A sample example file for setting the username,pwd and opening the ftp connection would be very helpful.
    Thanks in advance.
    Regards,
    Narendra.

    Rewrite your script as follow:
    open 134.133.210.24
    nkamar narendra
    Save it as ftpcommand.scr then call it.
    C:\>ftp -s:ftpcommand.scr
    If this still does not work try rewritting the script as follow:
    open 134.133.210.24
    user nkamar
    password narendra
    Save it and try again.
    Hope this works.
    ER

Maybe you are looking for

  • Can't get Apple watch and iPhone 5S to communicate over wifi.  Any suggestions?

    one feature of the watch I'm very interested in is the ability for it to communicate over wifi to my phone.  Put the phone down or be charging it in another room and still use the watch. So far it works fine Bluetooth but I haven't had any success wi

  • How to get the current date using HTMLB JSP page

    Hi All, I developed an iview with several fields using PDK, I would like to know how can I include for a date field a dynamic value witch in this case is the current date. <hbj:inputField id="Date" type="date" maxlength="10" showHelp="TRUE" required=

  • Web-based utility will not load on new wet54g ethernet bridge

    I just got a WET54g ethernet bridge to connect my bluray player to my existing network (wrt54gs router).  I cannot get the setup cd to recognize the bridge connected to the laptop or the router.  I thought that it would be no problem, just use web-ba

  • ALE Filter Group

    Hi Everybody, I have a question: Anybody could tell me how is the possibility to extend the standard filter in the ALE distribution model? At this moment you can only add a filter on controlling area and I would like to have one for the field Logical

  • Adobe Acrobat 8 phone activation

    I have Adobe Acrobat 8.0 installed on a Windows 2003 server. It was working fine, but is now prompting again for activation. The activation over the internet option does not work. Phone activation appears to no longer be supported. The url qouted in