0

I have two scripts. First script creates .csv files which are used as input for second script.

Can someone please let me know what additional steps I need to write in between below two lines so that second script will only start execution when first script has completely written all the files in .csv format.

start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_EXTRACT.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_EXTRACT.CONF"
start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_DATA_MAP.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_DATA_MAP.conf"
Mofi
  • 46,139
  • 17
  • 80
  • 143
orj
  • 53
  • 1
  • 1
  • 6

2 Answers2

1

You could try something like this. It loop untill the process "BES_EXTRACT.exe" is finished. when the task is running %ERRORLEVEL% will be "0" when the task is finished %ERRORLEVEL% will change to "1" and the loop will end. so when "BES_EXTRACT.exe" is finished %ERRORLEVEL% will change to "1" and "BES_DATA_MAP.exe" will start

Echo Date:%date% Time:%time% >> error.txt
    @echo off 
    (
    Echo Date:%date% Time:%time%
            start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_EXTRACT.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_EXTRACT.CONF"
             :loop
            for /f "tokens=2 delims=: " %%a in ('tasklist ^| find "BES_EXTRACT.exe"' ) do (
                if "%ERRORLEVEL%"=="0" (
                    ping -n 10 localhost > nul 2>nul
                    goto loop
                )
            )
            start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_DATA_MAP.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_DATA_MAP.conf"
        ) >> Output.txt 2>> error.txt

Explanation the the for loop uses the "tasklist" and the find command to check if the task "BES_EXTRACT.exe" is running if it is running it sets %ERRORLEVEL% to "0". If the %ERRORLEVEL% is "0" the script will ping yourown PC 10 times then go back and start the for loop again the Ping command is only there to count 10 Seconds (each ping is 1 second) then when the first script is finished the for loop will set %ERRORLEVEL% to "1" which ends the loop and starts the second script. This is a short explaination of the script if you require more of an explaination let me know :)

Badradish
  • 196
  • 1
  • 13
  • @Varlox thanks a ton.I am entirely new to batch scripting so could you please do me a favor and make me understand your script.especially the ping part, why it is neccesary. – orj Aug 19 '14 at 13:29
  • Thanks again for the detail explanation, now i have understood the script completely. just few more doubts, first is how i can hit enter in the batchscript through command line,how i can take output of the entire batch script alongwith the corresponding date and time and last doubt is about how i can redirect errorlog of entire batchscript to particular logfile..thanks Again for your great help :) – orj Aug 19 '14 at 14:11
  • look at this post for sending keys through batch http://stackoverflow.com/questions/17038282/press-keyboard-keys-using-a-batch-file as for outputing the output and erros in to diffrent files i have edited my script above "output.txt will hold normal file output and "error.txt" will hold any errors that the script has. and by date and time do you mean system date and time ? – Badradish Aug 19 '14 at 14:35
  • ok Varlox i have understood the way output can be redirected and the hit enter part.Regarding appending the logs file alongwith date and time , i am refering to teh system date on which i am running this script. – orj Aug 19 '14 at 14:41
  • i have edited the script above to add the date and time the script was run to the "output.txt" and "error.txt". – Badradish Aug 19 '14 at 14:51
  • this script is not printing the date and time in both log files if i redirect output and error logs inside this script like you have shown in you example.But if i keep both echo statement which are printing current date and time inside the batch script and then while running the script via command line i pass 1>> output.txt 2>> error.txt as argument to the script then script is only passing logs but not the date and time.Could you help me to print both logs and date and time in the log files. – orj Aug 22 '14 at 10:14
  • nopes , by doing this just the output file is getting written by date and time not the error file also the output and error logs are not getting written to output.txt and error.txt. i have tried to run this script by passing >> Output.txt 2>> error.txt as argument to the script via command prompt and it worked . But as i have mentioned in my earlier reply only logs are being written into the corresponding files not the date and time..Could you please assist me in achieving both things that is corresponding files getting written first by current date and time followed by actual logs. – orj Aug 22 '14 at 11:02
  • @Varlox thanks a trillion :) its working perfectly when i am trying to manually run the script through cmd but when i am trying to schedule the same script using task scheduler its only writing date and time in the error and output logfile , Could you guide me if anything needs to be changed so that task scheduler will execute it in the same way as i am doing to through command promt manually... – orj Aug 22 '14 at 12:36
  • can you let me know how to mark my questions as answered..i am new to this.. :( – orj Aug 22 '14 at 14:44
0

Have you tried it without the start command?
Normal command line programs will pause until done before the next line is executed.

@echo off
"D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_EXTRACT.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_EXTRACT.CONF"
"D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_DATA_MAP.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_DATA_MAP.conf"
foxidrive
  • 40,353
  • 10
  • 53
  • 68