1.

Solve : tasklist & findstr batch file problem?

Answer»

Hi all!

I'm looking for some help with an issue thats driving me crazy!

I'm trying to add some additional functionality to a batch file I use to create propriety application backups from many different PC's. Basically, I'm trying to automatically copy the backup from the C:\Backups to a directory on my thumb drive.

When the script gets to tasklist and findstr it errors out with xxx is not recognized as an internal or external command.... But if I cut and paste the code into a different batch file it works fine. However, if I call the new working batch file from the old one it fails.

Here's the code. The stuff above the REM !!!!!!!REMOVE ALL ABOVE!!!!!! is just there so that I can test the code before adding it to the existing batch file. I highted the problem area.

MANY THANKS!!!

Chris

This is the PART of the code I'm having a problem with:

Code: [Select]
 tasklist /fi "imagename eq SysBackup.exe" /fo list > C:\WINDOWS\System32\WP1\data\tlist.txt
 findstr SysBackup.exe C:\WINDOWS\System32\WP1\data\tlist.txt

Here's the entire code. The stuff above the REM !!!!!!!REMOVE ALL ABOVE!!!!!! is just there so that I can test the code before adding it to the existing batch file.

Code: [Select]echo off

SET PATH=C:\Konicaminolta\CS-2

REM Get Date and time and make into variables
 
 SET DAY=%date:~4,2%
 SET Month=%date:~7,2%
 SET YEAR=%date:~10,4%
 SET HOUR=%time:~0,2%

 
  REM Checks to see if hour is a single digit,if so a zero is place infront.
 
  if /i %HOUR% LSS 10 (

   SET HOUR=0%time:~1,1%

  )

 SET MIN=%time:~3,2%


REM Make new file name from variables

 SET NF=%DAY%-%MONTH%-%YEAR%_%HOUR%hr%MIN%min

REM Make new dated backup directory and System directory for System files

 md c:\Backups\%NF%
 md c:\Backups\%NF%\System

REM Copy System Folder
 
 copy %PATH%\Env\System C:\Backups\%NF%\System



copy C:\Backups C:\Backups\%NF%

REM !!!!!!!REMOVE ALL ABOVE!!!!!!


REM Finds Vindaloo's drive Letter and makes it into a variable.
 
 SET LETTER=%CD:~0,-20%
 SET SITES=%LETTER%:\StrongBow\Sites\


REM Looks to see if BU_Destination.txt exists or not.
REM If it exists then it turns it's contents into a variable.

 if exist C:\WINDOWS\system32\WP1\data\BU_Destination.txt (
 
  SET /p TEXT=<C:\WINDOWS\system32\WP1\data\BU_Destination.txt
  GOTO CREATE_BU_PATH

  )


:CREATE_BU_PATH


REM Makes variable for the path to the correct Backup directory on Vindaloo.

 SET BU_PATH="%SITES%%TEXT%\%NF%"


REM Make new dated backup directory and System directory Backup on Vindaloo.

 md %BU_PATH%
 md %BU_PATH%\System

REM Checks to see if Initial Backup is complete.

sleep 10

:CHECK_BU_PROG

sleep 5

 tasklist /fi "imagename eq SysBackup.exe" /fo list > C:\WINDOWS\System32\WP1\data\tlist.txt
 findstr SysBackup.exe C:\WINDOWS\System32\WP1\data\tlist.txt
 if %errorlevel%==1 GOTO COPY_BU

GOTO :CHECK_BU_PROG


:COPY_BU

REM Copy New Backup onto Vindaloo

 copy C:\Backups\%NF% %BU_PATH%
 copy C:\Backups\%NF%\System %BU_PATH%\System
Try this:
Code: [Select]For /F "tokens=1" %%i In ('Tasklist /NH /FI "IMAGENAME EQ SysBackup.exe"') Do Set sb=%%i
If /i %sb%==SysBackup.exe (Echo It's RUNNING) Else (Echo Doh!)
Thanks for the help! I modified your code to whats bellow and it works perfectly in it's own batch file but as soon as I add it to the existing file I get the same ERROR!

'Tasklist' is not recognized as an internal or external command, operable program or batch file.

File A which contains only the few lines testing to see if SysBackup.exe is running and File B that contains the entire script INCLUDING the exact same code in file A are both in the same directory on my thumb drive. But file errors? I just don't get it!!!

Code: [Select]:LOOP

SET sb=0

sleep 1

For /F "tokens=1" %%i In ('Tasklist /NH /FI "IMAGENAME EQ SysBackup.exe"') Do Set sb=%%i

IF %sb%==SysBackup.exe (

GOTO LOOP

)
Here's your problem

Code: [Select]SET PATH=C:\Konicaminolta\CS-2
I am not sure if you realise that PATH is a system variable which stores a semicolon-delimited list of folders where executables are stored. If an executable program or script is in the current folder, or a folder listed in the PATH variable, you can call it by its name alone. Otherwise you need the full path and filename. If you change the PATH variable, like you have in that batch file, most external commands (like Tasklist) won't work, and you get this message:

Code: [Select][Program or command name] is not recognized as an internal or external command, operable program or batch file.
The standard Windows XP PATH variable contents is

Code: [Select]C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem
So choose a different name.



THANKS! That was it!!!



Discussion

No Comment Found