0

I wrote a short batch file for restarting two services every night and write some lines to a txt-file in the same folder. According to the history of the scheduled task the task ran succesfully, but the txt-file is not created.

At first I thought this was beacause of permissions, but when I escalated the permissions of the user running the task to max on both the batch file and the folder, the result stayed the same.

If I run the batch-file manually it does what it's supposed to do.

What am I missing here?

Source:

@echo off
set now=%date:~6,4%%date:~3,2%%date:~0,2%

@echo. >>servicerestartlog.txt
@echo.%now% >>servicerestartlog.txt
net stop "IntegratorService"
IF ERRORLEVEL 0 @echo STOP INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo STOP INTEGRATOR FAILED>>servicerestartlog.txt
net stop "SchedulerService"
IF ERRORLEVEL 0 @echo STOP SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo STOP SCHEDULER FAILED>>servicerestartlog.txt

net start "IntegratorService"
IF ERRORLEVEL 0 @echo START INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo START INTEGRATOR FAILED>>servicerestartlog.txt

net start "SchedulerService"
IF ERRORLEVEL 0 @echo START SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 @echo START SCHEDULER FAILED>>servicerestartlog.txt

exit
TM89
  • 62
  • 1
  • 11
  • 1
    You are not indicating the path to the log file, so, probably, the current active directory is not what you think. – MC ND Nov 26 '14 at 07:52
  • yes, that seems to be the problem. It seems I just had to set the "Start in"-argument when editing the action to change the current active directory. – TM89 Nov 26 '14 at 07:55

1 Answers1

0

Solution that worked for me:

In addition to the path to the script I wanted to run I had to add the folder the script was supposed to start in. This can be set in the Start in (optional) - textbox under edit action. Seems it's not so optional after all...

TM89
  • 62
  • 1
  • 11
  • 1
    It is optional if the file references are not relative. All relative file references depend on what the current active directory is, not on where the batch file is located. Just imagine you call the batch file placed some where in the path while you are working in another directory. Where will the file be created? – MC ND Nov 26 '14 at 07:55
  • strange part is that I didn't use relative file reference. However, it still needed the Start in parameter to be set. – TM89 Nov 26 '14 at 12:27
  • 1
    Yes, you did. A reference to a file without a full path is a relative reference. You are using `>> servicerestartlog.txt`, so, as there is no path in the file reference, it is assumed that the file will be placed in the `current active directory`, not the folder where the batch file is placed. – MC ND Nov 26 '14 at 13:15
  • oh, I misunderstood completely! of course! It makes perfect sense! – TM89 Nov 26 '14 at 13:16