Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Using a .bat file to run another .bat file - 2nd .bat file (fails)

22 Aug 2013   #1
jfk92

Various - W7 32bit, 64bit
 
 
Using a .bat file to run another .bat file - 2nd .bat file (fails)

Hi,

I am using two .bat files together. The first .bat file runs on a timed scheduled task (something like 3pm daily) and is simply a warning/informational message and then if the user hit's "any key" it will close the window/complete the execution and as a result will call a second .bat file. (if they close the first DOS .bat prompt window the second will not be called) The second .bat file runs a series of backup exercises. Namely mail as well as a single folder on the machine. Here is my issue:

If I manually execute the first .bat file, the 1st dos window opens, I hit any key - the window closes and the second backup .bat file executes beautifully. (I would have mail/files closed) When the first .bat file is called from the scheduled task, i(f the scheduled task opens the first file) and then before hitting 'any key' in the active DOS window, I click out of the prompt to close mail and any open files I have that are included in the backup, THEN activate the DOS window, press return - the second file opens and "runs" but doesn't backup - it acts as it would if I had the outlook mail open (skips the backup).

It seems that if I take focus off the first DOS prompt that pops up to close mail/files then activate it to execute the second .bat file it 'skips' the execution of the second...it'll run it - the second DOS screen pops up and scrolls through the commands but no backup is actually done.

I'm perplexed here! I very much appreciate anyone's thoughts/input on this one. Thank you very much.

John


My System SpecsSystem Spec
.
22 Aug 2013   #2
MilesAhead

Windows 7 32 bit
 
 

If you post both the .bat files then perhaps we can see what is happening.
My System SpecsSystem Spec
22 Aug 2013   #3
jfk92

Various - W7 32bit, 64bit
 
 

Absolutely - it works great if I open the 'prompt' manually OR if it fires and I don't have outlook or anything open and can just hit a key so it triggers the second file execution and backup. but if I have to 'unfocus' the first DOS prompt to close outlook or files before 'regaining focus' of it to hit a key to continue - the execution happens but nothing actually backs up...so confused.

Prompt file here:

@echo PLEASE CLOSE OUTLOOK EMAIL AND ANY OPEN FILES YOU STORE IN THE "VITUSA" FOLDER ON YOUR MACHINE FOR A BRIEF DATA BACKUP.
@echo *******
@echo *******
@echo PRESS ENTER ONLY AFTER OUTLOOK/FILES HAVE BEEN CLOSED.
@echo *******
@echo *******
@echo IF YOU DO NOT WISH TO BACKUP YOUR FILES AT THIS TIME THEN CLOSE THIS WINDOW BY CLICKING ON THE 'X' IN THE UPPER RIGHT CORNER OF THIS POPUP.
@echo *******
@echo *******
PAUSE

Call C:\Backup.bat





and backup file (called bat file) here:


::Create the Log file of bat file execution
::
::
Echo >U:\BackupLog.txt


:: Outlook file compression and backup
::
::
for %%A in (C:\Users\%USERNAME%\AppData\Local\Microsoft\Outlook) do "C:\Program Files (x86)\7-Zip\7z.exe" a -t7z -mx5 "U:\outlooknew" -xr!*.bat "C:\Users\%USERNAME%\AppData\Local\Microsoft\Outlook">>U:\BackupLog.txt
REN "U:\%USERNAME%outlook.7z" "outlookold.7z"
REN "U:\outlooknew.7z" "%USERNAME%outlook.7z"
DEL "U:\outlookold.7z"



::User file compression and backup
::
::
for %%A in (C:\Users\John\Documents\Vitusa) do "C:\Program Files (x86)\7-Zip\7z.exe" a -t7z -mx5 "U:\Vitusanew" -xr!*.bat "C:\Users\John\Documents\Vitusa">>U:\BackupLog.txt
REN "U:\%USERNAME%Vitusa.7z" "Vitusaold.7z"
REN "U:\Vitusanew.7z" "%USERNAME%Vitusa.7z"
DEL "U:\Vitusaold.7z"



::Backup the OneNote notebook to the U:
::
::
xcopy C:\Users\%USERNAME%\Documents\"OneNote Notebooks"\Vitusa U:\"JK OneNote Backup"/s/e/i/y>>U:\BackupLog.txt
My System SpecsSystem Spec
.

23 Aug 2013   #4
MilesAhead

Windows 7 32 bit
 
 

From what you say it sounds like it sees the outlook files as in use by another process. I don't know why it doesn't give an error though.

edit: instead of .bat you could get a bit more sophisticated using a scripting language. AutoIt is easy to learn. AutoHotkey_L is more powerful. And there's always the MS ones such as powershell and VBScript.

The AutoIt and AutoHotkey_L packages are very small. Typically a compiled program is around 300 KB or less. Both have forums where you can ask for help if you get stuck.
My System SpecsSystem Spec
23 Aug 2013   #5
maxseven

Windows 7 Home Premium 64bit 6.1 Build 7601 (SP1)
 
 

Couple longshots that are easy to try:

1. Rename the 2nd file Backup.cmd (and Call it as such of course)

2. Wrap the 2nd command into a vbs file thusly so its window doesn't show at all:

-- Create a .VBS file e.g. Backup.VBS with these lines:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Backup.cmd" & Chr(34), 0
Set WshShell = Nothing

-- Now from the 1st command Call C:\Backup.VBS

This solved a similarly odd problem for me, though honestly I am using AutoHotKey to call the .VBS commands. Again, the VBS magic is a generic method I found which simply runs (any) .bat file w/o causing a Command window to open.
My System SpecsSystem Spec
23 Aug 2013   #6
jfk92

Various - W7 32bit, 64bit
 
 

thank you for the suggestions - I'll give them a try. curious though - I am using the 1st command prompt a the user interaction to decide if they want/are ready to backup at that time or not...if the vbs option hides it completely that would not be the effect I wanted.....
My System SpecsSystem Spec
23 Aug 2013   #7
jfk92

Various - W7 32bit, 64bit
 
 

MilesAhead - I think you just gave me an avenue to pursue - I've been saying it as the possible issue/action but not realizing then that might be the problem to address! lol. if the O/S is viewing Outlook as still getting used perhaps I need to add a kill-cmd to the outlook just prior to calling the second .bat file....perhaps there is some writing that goes on immediately after closing outlook and I need some time before the second .bat fires if I can't kill it manually. thx. I'll have to bring up the process manager and see if outlook is still there when I close the application from the user side! thx!
My System SpecsSystem Spec
23 Aug 2013   #8
MilesAhead

Windows 7 32 bit
 
 

Or you could try inserting a delay in the 2nd batch file with this line:
PING 127.0.0.1 -n 5 >nul

Depending what you read the number after the -n is approximately the delay in seconds, or seconds plus 1. IOW, using 5 as shown should get at least a 4 second delay. That may give the system time to "let go" of the files after the app is closed.
My System SpecsSystem Spec
24 Aug 2013   #9
maxseven

Windows 7 Home Premium 64bit 6.1 Build 7601 (SP1)
 
 

Quote   Quote: Originally Posted by jfk92 View Post
I am using the 1st command prompt a the user interactio...if the vbs option hides it completely that would not be the effect I wanted.....
If you read my suggestion it said "the 2nd command".
My System SpecsSystem Spec
03 Sep 2013   #10
jfk92

Various - W7 32bit, 64bit
 
 

Quote   Quote: Originally Posted by maxseven View Post
Quote   Quote: Originally Posted by jfk92 View Post
I am using the 1st command prompt a the user interactio...if the vbs option hides it completely that would not be the effect I wanted.....
If you read my suggestion it said "the 2nd command".
thx but unfortunately wrapping the second command into a vbs file doesn't solve the issue either. Same behavior exhibited - unfortunately the only way is to manually launch the prompt and fire the second command set - any 'loss of focus' of the first prompt seems to hose the success of the second.....thx anyway.
My System SpecsSystem Spec
Reply

 Using a .bat file to run another .bat file - 2nd .bat file (fails)




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
when open a word file or pwrpnt file another file is opens
God bless you, I am not a computer person please help me to fix the problem I have. Every time I open a word, power point and note pad program another file is opens with that (with a infinity sign in the front with the same extension ) is that a thread or how can I stop this thank you...
Microsoft Office
CBS.log file: Getting a usable txt file and interpreting the file
First, what does "CBS" mean in cbs.log? Does the cbs.log file show only errors? I create a cbs.log file a lot, so if there are errors, I'd like to correct them. However, my computer seems to be working just fine. sfc /scannow shows everything is OK. I've tried findstr /c:""...
Performance & Maintenance
5.4 GB file fails to download
Hello! I'm trying to download 5.4 GB file from Google Drive and it fails at some point after 2/3. I tried to use several browsers but still the download fails with an error: "the file could not be saved, because the source file could not be read." Please help, i need it for my work badly! ...
Network & Sharing
hidden file of docx file created with ~$name of file.docx file
whenever I open docx file there is hidden file ~$name of file.docx created. which type of file is that? Is it in virus, maleware. for example If I open house.docx file then ~$house.docx file created which is hidden form. I had saw this file when i select show all hidden file option. when i try to...
Microsoft Office
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
How do I change a file's file type (not only file association)?
I need to change a zip file to an epub file. I have heard this can be done, but when I add the .epub after the file name, I notice the file is still actually zip type file when I right click properties. This is causing a problem when I try to open it in in different ebook reader programs. I...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 17:38.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App