• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Batch File Not Running

Experts,

I have a DOS batch file that I use to run nightly backups to a USB key.  I have "sub" batch files in a child directory that are called from the main batch file (attached).  

When I attempt to call these "sub" batch files, I get an error saying they are "not recognized as an internal or external command".  

What's going on?
REM Copies from computer to USB key



REM Get rid of all .obj files.
Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.obj"


REM Get rid of all .log files.
Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.log"


REM Get rid of all .tmp files.
Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.tmp"



REM Get rid of all KT databases over six weeks old.
Call "C:\Program Files\MyBatchFiles\utility\DeleleteMDBsOverSixWeeksOld.bat"




REM Get rid of all executables before a given date.
Call "C:\Program Files\MyBatchFiles\utility\DeleleteEXEsOverSixWeeksOld.bat"



REM Delete the "My Desktop Apps" folder under \Knowledge Tracker if it exists.
RD "c:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\My Desktop Apps"


GOTO END



REM Copy all desktop app files.
c:
cd\
cd "Documents and Settings\cemich\My Documents\My Desktop Apps"
xcopy *.* /S /Y /D /H /I "f:\Documents and Settings\cemich\My Documents\My Desktop Apps"



c:
cd\
cd "Documents and Settings\cemich\My Documents\Work"
xcopy *.* /S /Y /D /H /I "f:\Documents and Settings\cemich\My Documents\Work"



cd\
cd "CCSMultiClient\CCSAdvantageDB\My Scripts\Utility"
xcopy *.* /S /Y /D /H /I "f:\CCSMultiClient\CCSAdvantageDB\My Scripts\Utility"



cd\
cd "C:\Documents and Settings\cemich\My Documents\Visual Studio 2008\Projects"
xcopy *.* /S /Y /D /H /I "f:\Documents and Settings\cemich\My Documents\Visual Studio 2008\Projects"



cd\
cd program files
cd MyBatchFiles


:END

Open in new window

0
NigelRocks
Asked:
NigelRocks
  • 5
  • 4
  • 3
5 Solutions
 
t0t0Commented:
what happens when you enter the command:

   dir /a-d "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat"

does it list the batch file and show "1 File(s)"?
0
 
Bill PrewCommented:
Based on the error, if it is happening on the CALL statment in the batch file you posted, then it sounds like the following files don't exist or can't be found.  Have you checked that they actually exist, and that you can view them?

"C:\Program Files\MyBatchFiles\utility\DeleleteEXEsOverSixWeeksOld.bat"
"C:\Program Files\MyBatchFiles\utility\DeleleteMDBsOverSixWeeksOld.bat"
"C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat"

If they do exist, then I would check the actual command that is indicated in the error message.  Maybe there is a command or program being run from the BAT files you call that is getting the error on a different program?  You should be getting an error message like below, where the quoted item is the command or program that can not be found.  Is it always one of the 3 BAT files mentioned above, or is it something different?

'foo.bat' is not recognized as an internal or external command,

~bp
0
 
t0t0Commented:
billprew

>> "Have you checked that they actually exist..."

Hopefully, you'll recognise the relevance of the DIR command in the previous comment.

Oddly enough, you took the next suggestion right from beneath my fingertips - could the CALLed batch files themselve CALL a subsequent batch file which cannot be found...

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
NigelRocksAuthor Commented:
If the error message doesn't mean what it's saying, there ARE calls to an .exe within each of the .bat files (attached).
That file exists in \Windows\System32, so I'm not sure why it wouldn't be found.

DelDate.exe /Q /F C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\ /M ww /T 6 /W *.exe /L

Open in new window

0
 
Bill PrewCommented:
==> NigelRocks

A couple of follow up items:

When the error shows up, it should show the name of the command it was trying to execute, in your case what does it show?

In the DelDate command line you showed above, you would need to quote the pathname since it has spaces, like below.  I don't think this is the cause of the error, but wanted to pass it along.

DelDate.exe /Q /F "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" /M ww /T 6 /W *.exe /L

One other thought, since you are running the original script from the task scheduler, could it be a case where the user credentials being used by the scheduled task have a different PATH than you have logged in?  You could add a SET command all by itself at the top of the executed batch file to see what the PATH is when it runs, along with other environment variables.

For further help with this error, could you please supply the actual log file from the scheduled task execution.

~bp
0
 
NigelRocksAuthor Commented:
Where am I running it from the Task Scheduler?  I'm launching it manually at the command line.  Am I missing something?
I've attached what the command window looks like after I've launched the program.

image.bmp
0
 
Bill PrewCommented:
Sorry on task scheduler, somewhere thought that was the case, my bad.

Okay, from that screen shot I can see the following. The first three calls (below) found the BAT file called, but when that BAT file ran it didn't locate the files you passed it. I'd also think that there is an ECHO OFF at the top of that BAT file that stops all command echoing from that first call forward, you could remove that for now to get a look at the details. You will have to determine what is wrong with the paths to the LOG, OBJ and TMP files. Do a

DIR ""C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker"
to see if any files show up.

Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.obj"
Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.log"
Call "C:\Program Files\MyBatchFiles\utility\DeleteFilesByExtension.bat" "C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\" "*.tmp"

Then on the next two calls the BAT files don't exist at the path specified. I suspect it's due to the typo in the middle of the word "Delelete" ?

Call "C:\Program Files\MyBatchFiles\utility\DeleleteMDBsOverSixWeeksOld.bat"
Call "C:\Program Files\MyBatchFiles\utility\DeleleteEXEsOverSixWeeksOld.bat"


~bp
0
 
NigelRocksAuthor Commented:
I thought I had fixed Delelete.
Anyway the path works fine with:
"C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker"  
I copied DelDate.exe from \Windows\System32 to the same directory as the sub bat files, but it still doesn't work.

image.bmp
0
 
Bill PrewCommented:
Can you comment out the ECHO OFF in DeleteFilesBy Extension.bat and rerun, posting the results?  It appears to be running that BAT file okay, but somewhere in it generating the file not found error.

The error seems to indicate that it can't find the files:

"C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\*.obj"
"C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\*.log"
"C:\Documents and Settings\cemich\My Documents\My Desktop Apps\Knowledge Tracker\*.tmp"

~by
0
 
NigelRocksAuthor Commented:
Those errors are OK, because files with those extensions should be deleted anyway.
0
 
Bill PrewCommented:
Okay, then in that case everything seems to be resolved.  Is there still something else that isn't working the way you want / expected?

~bp
0
 
t0t0Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now