Running bat file in Child Thread

Hi
Please first of all i will tell you my application flow.
I have an application you can say Parent Process/application , In execution of this Process or thread my application start/run batch file before dying using "exec() funtion" .In batch i have some scripts.and after initiating batch command my application main process ends up.
Now problem is
I am not sure that child process or Batch script which main program called is alive when my main application closed or its running?
i want to see its output on console?
Is it possible that Parent Thread ends up and child is still running , how can i achieve this .
OR is it possible that i create seprate thread to start batch and my main thread ends. and i will show batch file output on console.

I'm having a hard time understanding what you're
saying, so here are a few general things that may be
relevant:Sorry for that , well you are very much near which i want.But Thanks
* Child threads can keep running after the thread
that spawned them dies. You don't need to do anything
special here.
* The VM will exit when there are no more non-daemon
threads running. So if you make all threads other
than your main thread daemons, then when main ends,
the rest of the threads will die and the VM will
exit. See Thread.setDaemon.Here in above two point i have confusion.that by VM you mean Parent process,
VM is parent process of all java programs that we run.please clarify this
Lets say VM is parent process than your first statement is no valid as in first you say that parent die it will not effect child threads.
well i have test this case with my program i write a program like
public class ThreadTest
     public static void main(String [] arg)
          Work work=new Work(1000);
          System.out.println("Main Thread Started"+work.isDaemon());
          work.setDaemon(false);
          work.start();
          System.out.println("Main Thread stopped");
class Work extends Thread
     int count=0;
     public Work(int cou)
          super("Workere");
          count=cou;
     public void run()
          while(count-->0)
               System.err.println("Worker Thread is running................");
}Now bydefault work thread is deamon,when all work thread steps executed program finished, tell me here as its concurent execution,
main is alive or die when it execute its all statements or it waits for work thread which it spawned.
Secondly when i change deamon to true, when main statements finished it also stoped work thread.mean work thread just print some messages.
Actually what i want is that, when my main progam ends up, before ending it spawned new thread which start batch script and i want to see its output on seprate screen just like when we run IE with exec it starts IE window.
Hope fully this time its clear

Similar Messages

  • Running bat files in java code

    Hi,
    I am trying to run a .bat file within java code like this.
    Runtime.getRuntime().exec("c:\\Test.bat");
    but no success. Could you please suggest how to run .bat file or simply a
    DOS command from java code.
    thanx in advance
    Deepak Garg.

    try this...
    n reply whether it worked or not......
    import java.util.*;
    import java.io.*;
    import java.net.*;
    try
    Runtime runtime = Runtime.getRuntime();
    Process process ;
    process= runtime.exec("./temp_install");
    //code to print command line replies
    InputStream stderr = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while((line=br.readLine())!=null)
    System.out.println(line);
    catch(Throwable t)
    t.printStackTrace();
    }

  • Running Bat file in Minimized Mode

    Hai All,
    I need to run bat file using Runtime, Bat file should run in minimized
    mode ...
    any one help me
    Regards
    Yuva

    Assuming it's windows...
    start /min mybatchfile.batOpen a command prompt and type "start /?" to see the params available.
    regards,
    Owen

  • How to write run.bat files

    Can anyone tell me how to write run.bat files to run java classes. Currently my run.bat file has the following two lines,
    c:\j2sdk1.4.1_02\bin\javac.exe *.java
    c:\j2sdk1.4.1_02\bin\java.exe questionnair
    But the class is not executed. Thanks in advance.

    you'll have to provide more details.
    Firstly, which package is the class a part of? and secondly, where on the filesystem is the root of the package?
    You might also benifit from placing the c:\j2sdk1.4.1_02\bin\ into the classpath.
    On a rainy day, check out the ANT tool, it will take care of all that crapola for you.
    newio

  • Help! problem running .bat files in browser

    HI! Hope you can help me!
    I have a simple applet that runs .bat files and retrieves the resulting information into a text box.
    To run those files I use:
    Runtime rt = Runtime.getRuntime();
    Process processo=rt.exec("C:/po2PrtMonitor.bat 04600105 ope >C:/infoPrt.txt");
    in wich "04600105","ope" and ">C:/infoPrt.txt" are parameters that the .bat file is expecting. When the file is ran it saves the resulting information on a simple .txt file, that I later read by using:
    fichResposta = new FileInputStream(fichRespostaPath[0]);
    When I run my applet on JDeveolper 9.0.2.822 is works perfectly, the problem is when run it on the browser.
    On the browser the applet executes the file by opening a MS-DOS prompt and when it finishes executing the file, the prompt closes automatically and doesn't send the information into the .txt file.
    My .bat file is something like:
    jre -cp PrtSrv20.jar sibs.deswin.prt.PrtMonGateway 10.46.1.22 5003 %1 %2 %3
    where %1,2%,3% are the above parameters given by the applet when the file is ran.
    If I run it on JDeveloper I get:
    C:\>jre -cp PrtSrv20.jar sibs.deswin.prt.PrtMonGateway 10.46.1.22 5003 04600105 ope
    PRTSES=04600105 HDR=0460010000000005 STA=OPENED TRF=ACTIVE TRP=CONN ILTS=15 Long postings are being truncated to ~1 kB at this time.

    Here is what is missing:
    ILT=0 MSQ=388 HDR=04.60.01.00.00.00.00.05.41.00.01.84. CMD=STRT-TRF
    When the applet is run on the IE broser what I get is simply:
    jre -cp PrtSrv20.jar sibs.deswin.prt.PrtMonGateway 10.46.1.22 5003 04601005 ope
    I have no idea as to what the problem might be! Do native methods work differently on the browser?! Could it be a problem on the deployment? A library not included on the deployment profile? Suggestions are very welcome.
    Hugo Rosas

  • Running bat files from JDeveloper

    hi
    Sometimes it could be convenient to run a bat file directly from JDeveloper.
    For example, the application in SQLAuthenticatorApp-v0.02.zip (see also forum thread "how to disable (or lock) users") has an Ant file BuildStuff/build-wlst.xml which has targets like "wlst.create-domain" and "create.wls-start-stop-bat-files", the last one resulting in some bat files which I have been able to configure to run from JDeveloper,
    see http://www.consideringred.com/files/oracle/img/2011/run-using-cmd-20110529.png
    The External Tool cmd configuration I use is shown in the screenshot
    at http://www.consideringred.com/files/oracle/img/2011/external-tool-cmd-20110529.png
    See also the blog post by John 'JB' Brock
    at http://blogs.oracle.com/jdevextensions/entry/how_to_extend_jdeveloper_without_writing_code
    - (q1) How can I configure the External Tool cmd to run in its own cmd (command) window outside JDeveloper?
    many thanks
    Jan Vervecken

    Hi Jan,
    It looks like this is going to be a bug from what I can see. After looking at it a little more this morning, not only does it not display the cmd window, but if you use the /k argument, it leaves the script running in memory. Look at your Task Manager after running a few times with /k
    I'll file a bug, and see if anyone has a work around or something that I missed.
    For now, it would appear this is not possible, and you will just have to see the result in the log window. I would not use /k as well. Stick with /c for now.
    Sorry for the inconvenience.
    --jb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Scheduled task won't run .bat file

    Hi. On Windows Server 2008 I have a scheduled task that calls a .bat file. The fist step in the .bat file is write to a log file to the same directory in which the .bat file exists. This allows me to find out if it is ever run. When the .bat file is run from a command prompt it runs as expected writing to the log file and completing its actions. My problem is that when I run the scheduled task manually or allow it to run when scheduled it appears to run but the .bat file is never run. No log file is ever created. The History tab in the properties of the scheduled tasks shows the task being started and running then completing with an operation code of 2. I've disabled the UAC for the user account. I've set the task to run as the Administrator user and verified the permissions for that user. I know the password is correct for the task because I can make changes to the properties and save those changes with the username/password. I'm at a loss for further troubleshooting steps. Can anyone point me in the right direction to figure out why these .bat files are not being run? 

    So I had this problem, I double clicked on the .bat and notepad opened the .bat.  I ran through this whole long and very absorbing thread of this forum.   I wanted to save the entries that were most helpful, so I copied and pasted into
    a notepad document (.txt)  I could not find a way to attach it here, so I copied and pasted that below. I called it a synopsis....  Did I spell that right?
    As you can see, I added my experience at the top (A and B).  The stuff I copied is noted with the original author. This is the first time I posted anything to these here microsoft forums, although I have been telling computers what to do for 40+ years. 
    So hope I did not break any social protocols here.
    ==================================== Begin ====================================
         Running A Dot Bat File in Windows Server 2008 Vista 7 etc and beyond V01
    ============================================================================
    This was created as a synopsis of the entries at the following forum location:
    http://social.technet.microsoft.com/Forums/en/winservermanager/thread/d47d116e-10b9-44f0-9a30-7406c86c2fbe
    A) manually
         This is an opinion added by Thomas Rock
        1) Open a command window (that would be cmd.exe)
        2) In the command window navigate to the directory containing the .bat file and it's dependents
               ex...  C:\Program Files (x86)\Bobs\Your\Uncle
        3) Run the .bat file by typing the name including the .bat extension (in the command window of course)
                 TheBatFile.bat
           Note: Using this method, the .bat file will run in the current command window directory (the directory where the .bat file is located)
                             (this is the key for getting it to run in the task scheduler... Start in folder option)
    B) The double click
                This is an opinion added by Thomas Rock
         1) Using Windows exlporer, find the .bat file
         2) use the mouse or other device to double click on the .bat file
         3) if it does not run (in my case the wordpad application opened the .bat file)
              a) make sure that the .bat file extension is associated with the program c:\windows\system32\cmd.exe
              b) make sure the profile you are using has rights to run the cmd.exe
              c) make sure the profile has the rights to the directories, the .bat and any other objects used or affected by the .bat file processing.
    C) As a task using task scheduler
         Proposed As Answer by Brian Vandemark Wednesday, September 02, 2009 9:36 PM
    1) Make sure that the task is set to "configure for Windows Vista or Windows 2008" on the first page of the task properties (under the "general" tab)
    2) Make sure that the task is set to "start in" the folder that contains the batch file:
          a) open the task properties
          b) click on the "actions" tab
          c) click on the action and then the "edit" button at the bottom. 
          d) In the "Edit Action" Window there is a field for "start in (optional)" that you set to the path to the batch file.
          e) be sure to include an end backslash for the start in path "C:\dir1\dir2\"    (the last backslash is not optional)
    3) Make sure that the task is running as an account that has explicit "Full access" permissions to all these things:
          a) the .bat file itself
          b) the folder containing the .bat file
          c) the target files/folders that are affected by the .bat script. 
               Note:  Inherited permissions did not seem to work.
    4) Make sure that the account running the task is a member of the local "administrators" group for this machine
    5) Make sure that the task is set to "run whether logged on or not"
    6) Tick the box "Run with highest privileges".    
           Note: Point 6 here was from Edson F. Lima Wednesday June 30 2010 1:35 PM
                      The original point 6 was moved to point 7.
    7) The Task should run successfully with expected output when you right-click on the task and select "run" 
            If it does that then it will run successfully when you are logged off.
    D) Still another way as a task using task scheduler
          Proposed As Answer byDarren Wallace Thursday, July 15, 2010 1:41 AM
    This has been bugging me for 6 or 7 months.
    I don't have admin rights to the box and the guy who does is very busy...
    so I've felt the range of emotions mentioned above.
    I tried most everything above as well. But what seemed to get my processes processing, was ...
       • on the General tab, I clicked the Change User or Group button
       • in Select User or Group (first smaller dialog box)  I clicked the Advanced... button
       • in the next Select User or Group (second bigger dialog box) I clicked the Find Now button
       • in the Search results I selected the Administrators (a group) and it returned SERVERname\Administrators into the "Enter the object name to select" entry in the previous dialog box
       • then I clicked OK and returned to the General tab above
       • the options to Run only when user is logged on and Run whether user is logged on or not are no longer available
       • then I made sure that the Run with highest privileges was checked
       • then I clicked OK and during the next scheduled time to run ... it ran
       Note: See note in A) Manually above.
    E) Task scheduler recommendation
         Proposed As Answer byTamusJRoyceThursday, December 01, 2011 3:42 PM
    I have found .bat and .cmd files do not run correctly either.
        My solution:  Don't run the batch file directly. 
           Have TaskScheduler run:  cmd.exe
              with parameter:  /C YourBatchFile.bat
             and start in: C:\SomePath\ (without quotes!) where C:\SomePath\YourBatchFile.bat exists. 
            And then select the radio button for it to run regardless if you are logged in or not.
    Exit errors may not be logged to the Event Log (they weren't when the .bat ran directly from Task Scheduler when I was logged in), so I find it best to manually log your own Event in case a error occurs and you want to send an email.
     REM Logs an event which causes eventlog to send an email when it fails.  Also, "/l application" needs to be lowercase.
    eventcreate /t error /id 203 /l application /d "your logged description."
    And then make a completely separate task with a trigger:  On an event.  Basic Selected.  Log: Application.  Source: EventCreate. Event ID: 203.  And have the action on this task send an email (attaching any generated log files, if needed).
    Hopefully helpful (took me 3 days to figure all this out...gar)
    ===================================== End ===================================
         Running A Dot Bat File in Windows Server 2008 Vista 7 etc and beyond V01
    ============================================================================
     

  • Run .bat file?

    Alright this won't seem to run my file, what am I doing wrong?
    try {
                String File = "mybat.bat"; // File specified
                Runtime.getRuntime().exec(File);
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } Thanks for any help.
    Edited by: Austin187 on Nov 5, 2008 2:30 PM

    .bat file will run without "/c", but here's what I was talking about
    private static void SlashCTest() {
              while (true) {
                   JFileChooser jf = new JFileChooser();
                   int res = jf.showOpenDialog(null);
                   if (res != JOptionPane.OK_OPTION) System.exit(0);
                   File f = jf.getSelectedFile();
                   Runtime r = Runtime.getRuntime();
                   //String cmd = f.getAbsolutePath();
                   String cmd = "cmd.exe /C \"" + f.getAbsolutePath() + "\"";
                   try {
                        Process p = r.exec(cmd);
                        InfoFetcher fetcher = IOUtils.loadData(p.getInputStream());
                        FetcherListener fl = new InfoFetcher.ToStandardOut();
                        fetcher.addFetcherListener(fl);
                        new Thread(fetcher).start();
                        fetcher = IOUtils.loadData(p.getErrorStream());
                        fetcher.addFetcherListener(fl);
                        new Thread(fetcher).start();                    
                   }catch (IOException ex) {
                        ex.printStackTrace();
         }Edited by: tjacobs01 on Nov 5, 2008 11:39 PM

  • Running .bat files from java applications

    Has anyone tried to run a .bat file from a java application?
    I know I can run java commands by getting the application's runtime, but I've a number of *.bat files I like to run from the application without having to extract the commands from the .bat files.
    thks,

    Crikey! You were answered very shortly after you posted your question, and you STILL haven't bothered to come back. And are you going to create a new userid the next time you ask a question, since bat2004 seems tied to this particular question?

  • Running bat-files from Java

    Hello,
    I have been trying to launch a bat-file from my Java code, running under windows, but with no success.
    Here is my simple code:
    Runtime.getRuntime().exec(new String[] {
             "C:\\temp\\test.bat"
          });This does nothing at all and generates no exception. Any suggestions?

    It seems java has a real problem with this... if you
    want to run another java program, for instance, you
    cannot do that either with String cmd="cmd.exe /C
    java myProgram"
    I need to pass parameters from one program into the
    program I'm going to open using java, that is why I
    need to call it from my first program. It can open
    executables and shortcuts, but has a real big problem
    doing things with the command line.No it doesn't have a problem with it. You just must be doing something wrong. By the way, since "java(.exe)" is already an executable, there's little value in wrapping that by the "cmd.exe" shell (unless you want to use the command shell for some reason such as passing the redirector (>) symbols to it to let it redirect stdout / stderr to a file)

  • Running .bat files from java code

    Dear Forum,
    I have seen numerous postings on the web about this question, still I have found no answer that works (for me)
    I�m trying to run a simple .bat file from a piece of java code , however it does not work. No error message , but still.
    Does anyone have a tip?
    best regards
    temuj
    try{
                String cmd = "cmd.exe C:\\mybat.bat";
                Runtime.getRuntime().exec(cmd);
    catch(IOException e){System.out.println("ERROR: "+e);}Message was edited by:
    temujin

    "cmd.exe C:\mybat.bat" is being passed to the OS for execution
    what happens when in a terminal/dos window you execute letter for letter:
    cmd.exe C:\mybat.bat
    The output will be identical to what is happening when java makes this call.

  • Where is the run.bat file?

    Hi,
    I have downloaded beanbuilder-0_6-alpha from https://bean-builder.dev.java.net/
    I am trying to install the bean builder going thru the readme file. I have extracted all the file but I cannot find "run.bat". Can anyone help me find this file.
    If this is not how I should go about installing the bean builder. Please guide me.
    Thanks,
    tick_tick

    Hi,
    You probably have the wrong classpath on your line:
    java -cp ... javafilename xml ruleset_nameSince the DocumentBuilderFactory can't be found.
    It is most likely included in one of the jar-files in the lib directory.
    /Kaj

  • Java virtual machine error: in running bat file!!!

    Hi experts!
    I have encounterd a problem . Could not figure out why I am having this. I hope at least I will get a clue /suggestion from any of you.
    I am creating a bat file from my java Application. Then I double click on the newly created bat file to run that. It gives me Java virtual machine launcher error:" could not find the main class, Progam will exit". I have a VB script, that also create the same bat file. but I dont have problem running that file manually. Even if I create the bat file manually(by typing), it ran well. It shows the error mesage only when I create bat file from my java Application. Instead of running the bat file manually, I tried to run it through my java application too(by Runtime.exec() ). But it shows me the same error msg.
    Why am I getting java virtual machine launcher error when I tried to run my bat file that is created from java Application? ANy clue? Please suggest me about how to resolve this.
    Regards

    Probably because (despite what you say) the contents of the bat file created by your Java application aren't the same as the contents of those other bat files.Yes contents are same. I create the bat file from my java Application. then I am trying to run that bat file manually. It gives me the specified error. But if I create the bat file manually (with the same content) and then run it manually. It works well.
    Any clue/suggestion

  • Run .bat file with arguments?

    Hi,
       I need to run the .bat file with parameters/arguments in Adode Indesign JavaScript. "File.execute()" executes the file using the appropriate application.It executes the .bat file suceessfully.But I am unable to pass the arguments.I need to execute the command like
    Eg : test.bat parameter1 parameter2
    var myFile=new File("c:\\test.bat");
    myFile.execute();
    The above statements works fine. Is it possible to execute the with parameters. Please suggest the solution to above problem.

    Hi,
    let VB start the *.bat. this works for me:
    #target InDesign
    doTheBat('START "" "C:\\Program Files\\Adobe\\Adobe Photoshop CS5.1 (64 Bit)\\Photoshop.exe"')//Start Photoshop, just a example
    function doTheBat ( _data ) {  
            try 
                var _file = new File('~/myTmpBat.bat'); 
            _file.open( 'w' );  
            _file.encoding = 'UTF-8';  
        _file.writeln ( _data );  
        _file.close();  
        //_file.execute(); 
        myVBScript = "Set WshShell = CreateObject(\"WScript.Shell\")\r"; 
    myVBScript += "WshShell.Run chr(34) & \"C:\\Users\\%USERNAME%\\myTmpBat.bat\" & Chr(34), 0\r"; 
    myVBScript += "Set WshShell = Nothing\r";
    myVBScript += "\r"; 
    app.doScript(myVBScript, ScriptLanguage.VISUAL_BASIC);
        }catch (e){  alert(e);
    Good luck
    Hans-Gerd Claßen

  • Run .bat file from Flex

    Hi,
    I'd like to execute a .bat file from Flex. I thought this piece of code should work but no luck
    fscommand("Exec", "C:\\Sandbox\\doSomething.bat");
    Can someone please point me in the right direction?
    Thanks in advance,

    Sandbox does not allow external apps to be run in Flex apps. AIR 2.0 may have this.
    If this post answered your question or helped, please mark it as such.

Maybe you are looking for