Running batch files in series, part 3

Hi,
I have 2 batch files called list1.bat & list2.bat which I execute using
runCmd( "list1.bat" )
runCmd( "list2.bat" )
Both of them contain the commands
dir d:\
dir c:\
echo endOfBatchFile
The idea is that the second one will not kick off before the first one is finished so I came up with the method below.
But what I expect to happen doesn't happen, usual stuff
ie I read a line from the proc input stream and stay in the loop until I read the line "endOfBatchFile"
but can't get this to work. Am I going about this the right way, or am I reading from the wrong stream
PS the method call proc.wait() doesn't work which is why I have to come up with another way to force the program to wait until the first batch file is done.
public static void runCmd( String cmd ){
     String s = null;
     try {
       Runtime rt = Runtime.getRuntime();
       Process proc = rt.exec(cmd);
       BufferedReader stdInput = new BufferedReader(new  InputStreamReader(proc.getInputStream()));
       while ((s = stdInput.readLine()) != "endOfBatchFile") {
          System.out.println(s);
     catch (Exception IOex) {
        System.out.println("Exception occured in runCmd method : "+IOex.getMessage());
  }

My guess is that the Process you create (let's call it process A) includes a command that spawns a second process (let's call it process B) and then returns immediately. This would be the case if you used "cmd /c something", for example, as the command for process A. So in this case, you can know by using Process.waitFor() that process A has completed. But you have no way of knowing anything about process B, in particular you don't get notified when it terminates.
Not unless process B is designed so that it produces some visible evidence that you could wait for. Examples: creating a file in a predetermined location. Sending you a message via e-mail or JMS or a socket. Writing a record into a database file.
PC²

Similar Messages

  • HOST IN 10g to run batch file on application server

    Hi,
    I am trying to deploy a form from 6i to 9i. the form use Host builtin to run batch file on machine. this works fine when i run form on client server environment. but when i run the same form after compiling in 9i and run on 3 tier model and try to run batch file from form it give me error that
    'ftp' is not recognized as an internal or external command,
    operable program or batch file.
    any suggestion?

    It could be because the Host session doesn't have any environment variables set i.e. there is no PATH variable, so it simply doesn't know where to look to find the 'ftp' executable. You could try supplying the explicit path of the ftp executable and see if that works. (This was a problem I had running Host commands on a Unix application server.)
    James

  • 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 thraugh java by passing parameters

    Hi
    I want to run a batch file by passing some parameters.
    Eg: copy.bat "D:\live\hoe.txt" "D:\test"
    while doing this from command prompt its working and i have written some java code for running this batch file.
    String live="D:\\live\\how.txt";
    String test="D:\\test";
    String bat="D:\\copy.bat";
    String[] command = new String[3];
    command[0] = bat;
    command[1] = live;
    command[2] = test;
    try {
    Runtime.getRuntime().exec(command);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    but this time its not copying the file;
    Please help.

    Just another cross poster.
    [http://www.java-forums.org/new-java/15005-running-batch-files-thraugh-java-passing-parameters.html]
    db

  • How to run batch file from oracle forms 9i

    Hi everyone.
    i have a data in csv file. i want to upload it to my database. i am using sql loader for it.
    i have made a batch file which run the sql loader and transfer my data to database.
    How to run batch file from oracle forms 9i.
    when i press the button, nothing uploads in my database. (when i simply run the batch file it works).
    here is my code
    Begin
    HOST('C:\temp\batchfile.bat');
    message('done');
    end;
    Thanks in advance
    regards
    sajid

    this is my log file, when i run manually.
    SQL*Loader: Release 10.2.0.1.0 - Production on Thu Jul 1 23:27:53 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Control File: file_to_upload.ctl
    There are 2 data files:
    Data File: sk.csv
    Bad File: sk.bad
    Discard File: none specified
    (Allow all discards)
    Data File: sk1.csv
    Bad File: sk1.bad
    Discard File: none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table KHAN, loaded from every logical record.
    Insert option in effect for this table: APPEND
    Column Name Position Len Term Encl Datatype
    SR FIRST * , O(") CHARACTER
    DATES NEXT * , O(") CHARACTER
    AGENT NEXT * , O(") CHARACTER
    COUNTRY NEXT * , O(") CHARACTER
    TRANSACTIONS NEXT * , O(") CHARACTER
    PKR NEXT * , O(") CHARACTER
    USD NEXT * , O(") CHARACTER
    BANK NEXT * , O(") CHARACTER
    Table KHAN:
    11088 Rows successfully loaded.
    0 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 132096 bytes(64 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 11088
    Total logical records rejected: 0
    Total logical records discarded: 0
    Run began on Thu Jul 01 23:27:53 2010
    Run ended on Thu Jul 01 23:27:54 2010
    Elapsed time was: 00:00:00.63
    CPU time was: 00:00:00.17

  • Unable to run batch files in my EP server

    Hi,
       I'am unable to run batch files(go.bat and configtool.bat) on my EP server.Anbody please give me a solution.
    With Regards
    Pradeep.B

    If your EP Server is on non-windows based environment then you cannot use go.bat & configtool.bat or else you can. If you are trying to execute these on unix based machines then you have to use go.sh & configtool.sh files.
    Pradeep

  • Can't run batch file in Windows 2008 R2

    Trying to run batch file (manually first) with powershell commands.
    Powershell commands work fine thru powershell but the batch file will not execute manually.
    I am trying to run as administrator.
    Is there a permission  or policy I may be missing?
    Thanks
    Dave
    Dave Kozlowski

    Hi,
    Some bat type command can't run in the powershell environment, you must confirm you have choiced the correct lunch tools.
    Hope this helps.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Unable to run batch file through BO XI 3.1 server

    IHi,
    I am unable to run batch file (.bat) from BO XI CMC. the batch file is running fine through command prompt but fails at server. Error msg is "Running this type of program is disabled by your administrator".
    Can you help?
    Thanks in advance,
    Avijit

    Have your administrator enabled the running of that type of program in the CMC?
    Sincerely,
    Ted Ueda

  • Can't run Batch files or Devnev (visual studio) - is not recognized .. command

    Getting the famous error :
    ... is not recognized as an internal or external command`*
    When & Where :
    not sure about the total range of the problem,
    Here I can't run batch files and "devneve.exe"
    sample Batch could be :
    @echo off   
    clr
    'clr' is not recognized ...
    **Here are the keynotes:**
     1. I run it as an admin (cmd)
     2. The Path variable seems to have anything needed, Powershell's path is also there sys32..v1
     3. I'm going into the current directory of devnev.exe ...
     4. ran also "devnev.exe"
     5. I don't have 2 cmd s in a known folder
     6. the autorun registries for command prompt were deleted
     7. the cmd extensions were disabled and re-enabled
     8. Avast IS 9 is running,
     9. The system seems to be fine
     10. all .Net frameworks are installed
     11. for a test jetAudio or ILDasm could be executed from the cmd
    Win 8.1 Pro , CPU i7, VS 2013 upd2

    thanks,
    this was one of the silliest problems I've ever encountered, my bad fault,
    the file is DevEnv not DevNev...!
    but about the clr, don't know from when I added them to my batches, but I'm sure the scripts were working correctly a time ago, maybe by a mistake I changed them, I thought it is the most known command, but I was wrong, there is a long time gap between me
    and DOS.

  • PDQ - run batch file on user current folder...

    Hi,
    I'm running batch file:
    cd %USERPROFILE%\AppData\Local\Microsoft\Windows\Temporary Internet Files\
    but it's not opening the current logged on user
    how to deploy it on current logged on user?
    thanks,,,
    This topic first appeared in the Spiceworks Community

    This is not working for me in Windows 8.  I have a shortcut to an EXE file located in"C:\Users\admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup".  If I set the shortcut to run as administrator (screenshot attached) then it does
    not run at all on startup.  If I uncheckmark "Run as Administrator" then it starts fine (but does not have enough privileges to do what it needs to do).  In Windows 7 this was not an issue since the current user was a local administrator and did
    not need to elevate its privileges further.
    Any ideas how I can work around this problem?  Thanks!
    Ugh... it won't let me attach a screenshot until my "account is verified", whatever that means.

  • Using JSP to run batch file - command launches excel but doesn't open file

    I have written a jsp on a server which runs a batch file. Every command line in the batch works fine except the following:
    CALL "C:\Program Files\Microsoft Office\Office\Excel.exe" C:\Temp\spreadsheet.xls
    I can see that a command prompt has been opened and an instance of Excel has been created, but it does not open the file.
    I tried running the batch file on its own. It worked fine. I tried putting the java code in the jsp into a java class, that worked okay too. I think it might be to do with the fact that the client is trying lauch the application through the web, but it's missing some information such as paths.
    I am totally running out of ideas.. please help

    I guess if I know JSP stands for Java Server Pages..
    I would most probably know it runs on servers.Yes, you might, but if you were assuming that the path you gave would always lead to an executable running on the client you'd have a problem. It's worth asking.
    I must admit it's probably not the best idea, but if
    you can give me some advice on that, that would be
    greatJSPs shouldn't have code in them that doesn't pertain to view. I'd wrap something like a system call or Runtime.exec in a Java Bean that you can test off-line without the JSP. Then have the JSP instantiate an instance, invoke its method, and display the value that's returned.
    You've read this, of course:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Everyone who uses Runtime.exec should.
    %

  • Windows task scheduler to run batch file running a java program

    I have created a batch file that runs my SendEmail program. The batch file is in the same directory as the java program. The only line in the batch file is
    java SendEmail
    This works fine from the command prompt but from the windows task scheduler it fails to function. Any help on how I can overcome this problem will be greatly appreciated.
    THanks

    Looks okay. The classpath is set, too, I guess? Btw, try running javaw instead of java. I may err, but I think it can show a console, so you can watch any error messages.

  • Strange behavior when using Runtime.exec() to run batch file

    I've been struggling with this for hours.
    I have a Swing application which upon clicking a button, I want to execute a batch file. This batch file itself uses a command window.
    When I use
    Runtime load = Runtime.getRuntime();
    load.exec("cmd /c start c:\\renew\\renew2\\bin\\win\\renew.bat");
    The program (Renew) will start up no problem, but when I exit Renew, the command window stays put. I want the command window to close. Running Renew stand-alone, upon closing Renew, it will exit the command window.
    When I use
    Runtime load = Runtime.getRuntime();
    load.exec("cmd /c c:\\renew\\renew2\\bin\\win\\renew.bat");
    or
    Runtime load = Runtime.getRuntime();
    load.exec("c:\\renew\\renew2\\bin\\win\\renew.bat");
    When I press the button, sometimes the Renew application will come up right away, sometimes the Renew application will come up after a very long delay, and most times, the Renew application will only come up after I have closed the Swing frame where the button is located. When I use this code, the command window that Renew uses is never visible.
    What I want is to simply have the Renew application behave the same exact way launching from my Swing application as when Renew is being run standalone.
    Any suggestions? Thanks so much.
    Sincerely,
    Will

    Getting rid of start makes the startup time very variable. Sometimes it starts up right away, sometimes after many minutes, most times only after I close my application.
    Thanks, Any other suggestions?
    (BTW, I have read the famous "When Runtime.exec() won't" article, and have tried its suggestions to no avail)
    Message was edited by:
    willies777

  • SQL 2008 Agent - run batch file not working

    Hello,
    I am having some strange issues with a batch file running out of SQL agent I'm hoping I can get some help with.
    The batch file's purpose is to send some log files to a SFTP server.
    The job has been working great for the past 3 weeks, however this morning it stopped working. The job doesn't error out, however the entire job completes in 00:00:00 duration and I'm given the following message 
    Date 4/7/2014 3:38:00 PM
    Log Job History (***Log Transfer)
    Step ID 1
    Server *******
    Job Name **** Log Transfer
    Step Name run batch
    Duration 00:00:00
    Sql Severity 0
    Sql Message ID 0
    Operator Emailed
    Operator Net sent
    Operator Paged
    Retries Attempted 0
    Message
    Executed as user: USERNAMERemoved . The step did not generate any output.  Process Exit Code 0.  The step succeeded.
    The batch file looks like 
    echo  *********************************
    echo  ** JOB EXECUTED %date% %time%  ** 
    if %errorlevel% neq 0 exit /b
    C:
    cd "C:\Program Files (x86)\WinSCP"
    winscp /console /script=G:\Batch\LogTransfer.txt
    call G:\Batch\LogTransfer2.bat
    echo ** COMPLETED %date% %time%  ** 
    echo  *********************************
    I have numerous other batch jobs running on this server, no other job has had this issue.  I have deleted and recreated both the job step and the entire job.  I have recreated the batch files from scratch.   I have also deleted the entire
    contents of the batch file and just simply put in echo **** and still received the message so I'm near positive it has nothing to do with the actual batch file.  
    I have reset SQL Agent, as well rechecked that the SQL Agent account has run batch rights granted to it.
    I moved the batch files to another folder, and they worked for about 4 runs until the same issue happened!!!
    The job does execute 100% perfect if I run it manually via batch or if I kick it off starting the job out of SQL.
    I am out of options here, does anyone have any ideas that could help me out?
    Thanks,
    Ryan

    Hello,
    Try to edit the step, and on the Advanced page of that step try to configure the job to create a log on the location you specify (Output file). Try to run the step again and examine the log created.
    Could you try to change the owner of the job to “sa” or to your Windows account? Maybe the SQL Server Agent account does not have access
    to the following folders:
    G:\Batch\
    C:\Program Files (x86)\WinSCP
    Alternatively, you can try to create a proxy account.
    http://technet.microsoft.com/en-US/library/ms190698(v=SQL.105).aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How to Run Batch files from inside Reports.

    Hi All,
    I have 2 questions.
    1) How to change the direction of the reports with Arabic orientation i.e Right to left Change without changing the registry.
    2) How to execute a batch file from report or before execution of the report i.e before opening the report.
    I want to set few environmental variables before opening the report. How do i achieve this?
    Request the forum community to discuss and help me out on this issue.
    Thanks in advance

    Thanks Inol
    Though my report is running NLS variable values given in the batch file is not getting picked.
    Here is my batch file contents. My NLS Variables are not getting picked in the reports. I want that to be picked up and the reports orientation should change automatically as per the NLS variables given in the batch file.
    Please go through my batch file code.
    set NLS_LANG                   = AMERICAN_AMERICA.UTF8
    set NLS_CALENDAR            = GREGORIAN
    set NLS_DATE_FORMAT      = dd/MON/yyyy
    set FORMS60_PATH           =   <Enter Relevant Path>
    set REPORTS60_PATH        =  <Enter Relevant Path>
    set PATH=%PATH%;c:\forms6i\bin
    set ORACLE_HOME             =   c:\forms6i
    set TNS_ADMIN                 =   c:\forms6i\NET80\ADMIN\TNSNAMES.ORA
    rwrun60.exe d:\DOTNETORION17_bin\elist_rg1.rdf userid=scott/tiger@thai P1=10Please help me out in getting this value picked and run the report.

Maybe you are looking for

  • Why can't you deauthorize just one computer?

    Why is the only choice in the store to deauthorize ALL computers with an appleid/iTunes store account?  My husband took my old mac book pro and removed all my info on it, but did not deauthorize the iTunes account first.  Now, my phone won't sync wit

  • How do you find the pixel dimensions of a photo to embed in Illustrator CC?

    We recently upgraded our software from CS3 to CC. I'm having trouble determining the pixel dimensions of the photo I want to embed in Illustrator. In our old work flow, we simply clicked on the object in Illustrator, and then opened a new document in

  • Can I reduce the message in the alert log ?

    Hi All, I receive lot of message in my alert log. Can I reduce the message in the alert log ? please help me Tue Sep 12 13:53:45 2006 ARC0: received prod Tue Sep 12 13:56:13 2006 LGWR: prodding the archiver Thread 1 advanced to log sequence 2105494 T

  • Video in button

    Im sure this is a basic question but I'm still getting familiar with DVDSP (I have spent more than a few hours in the manual and trying things). So, I can get a small video clip in a button, but I cant get it to loop. Is it possible? How? If not, sam

  • Read/write access on external drive set to none; can't see drive to change

    I was learning about profiles and permissions and set the Read/write access on my external drive to none. I wanted to protect my guests from accidentally viewing private files. I thought I was doing it for that profile only, but now I can't see the d