1

I am on Windows 7 Professional. I have the following files in C:\script.

clamav_daily_scan.bat
log_email_clamav_daily_scan.bat
email.vbs
log.txt

log_email_clamav_daily_scan.bat

@echo off
@echo set variables
SET DATETIME=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%
SET LOG_DIR="%PROGRAMFILES(X86)%"\ClamWin\bin\daily_scan\log
SET LOG_FILENAME=clamscanlog_%DATETIME%.txt

@echo start daily scan
C:\script\clamav_daily_scan.bat > %LOG_DIR%\%LOG_FILENAME%

@echo send result
C:\Windows\SysWOW64\cscript.exe C:\script\email.vbs %LOG_DIR%\%LOG_FILENAME%

When I execute log_email_clamav_daily_scan.bat on cmd, it only stop until start daily scan.

C:\script\log_email_clamav_daily_scan.bat
set variables
start daily scan
bittersour
  • 937
  • 2
  • 11
  • 32
  • First, remove `@echo off` or change it to `@echo on` or comment it out with command `rem` at beginning. Second, open a command prompt window. Third, type name of batch file with full path in double quotes. Fourth, press ENTER or RETURN and now with running the batch file from within a command prompt window instead of double clicking it, you can see the error message(s) output as the window remains open on an error. And you see also the command lines really executed after processing by command processor. That's what we call debugging a batch file. – Mofi Nov 15 '16 at 06:35
  • I would be really surprised if the batch file executed with your user account has write permissions on directory `"%ProgramFiles(x86)%\ClamWin\bin\daily_scan\log"`. And please note where I put second double quote here and where you put second double quote in string in your code. And why do you use `C:\Windows\SysWOW64\cscript.exe` instead of `%SystemRoot%\System32\csript.exe` to run 32-bit or 64-bit console version of Windows Scripting Host depending on batch file executed from 32-bit or 64-bit command interpreter depending on being started from a 32-bit or 64-bit process? – Mofi Nov 15 '16 at 06:51
  • there is a similar question: is duplicate? http://stackoverflow.com/q/1103994/4291215 – loadingnow Nov 15 '16 at 06:52
  • Please read answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](http://stackoverflow.com/a/26388460/3074564) Then you hopefully understand that `SET LOG_DIR="%PROGRAMFILES(X86)%"\ClamWin\bin\daily_scan\log` is not good, and also `SET LOG_DIR="%ProgramFiles(x86)%\ClamWin\bin\daily_scan\log"` is not good because of `%LOG_DIR%\%LOG_FILENAME%` which should expand to `"C:\Program Files (x86)\ClamWin\bin\daily_scan\log\clamscanlog_%DATETIME%.txt"` with a double quote at begin and another one at end of __concatenated__ path and file name. – Mofi Nov 15 '16 at 06:52
  • And read answer on [How to call a batch file that is one level up from the current directory?](http://stackoverflow.com/a/24725044/3074564) explaining the difference on running from within a batch file another batch file without using `call` and with using `call`. – Mofi Nov 15 '16 at 06:55

1 Answers1

0

use

call C:\script\clamav_daily_scan.bat > %LOG_DIR%\%LOG_FILENAME%

without call your script will end halfway

loadingnow
  • 597
  • 3
  • 20