Schedular just won't work

  • Thread starter Thread starter livetohike
  • Start date Start date
L

livetohike

Hi,
I can't get the simple batch below to run from the scheduler via right-
click/Run. (Nor does it work if I schedule it to run).

When I run it from Explorer or cmd window it works fine.
I am running it w/ an administrator account and password (but have
tried other accounts)

Batch file contains the following single line:
echo %date% %time% >> Test.txt

I can see the black cmd window 'flash' so it appears to run, but does
not write to the file.
The batch and output file (Test.txt) live within the MyDocument folder
of the user running the batch.

Test.txt should contain (and does when run manually):
Thu 05/22/2008 17:58:08.98 moormansd
Thu 05/22/2008 17:59:01.28 moormansd
etc.

Scheduler shows exit status of 1 and a correct "Last Run Time"

The Advanced/View Log shows:
"Schedule Test.job" (ScheduleTest.bat)
Started 5/22/2008 5:54:36 PM
"Schedule Test.job" (ScheduleTest.bat)
Finished 5/22/2008 5:54:36 PM
Result: The task completed with an exit code of (1).

What am I doing wrong!
Thanks
 
"livetohike" <moormansd@gmail.com> wrote in message
news:2d47da9b-07c7-499e-b1ed-11539956d2d9@e39g2000hsf.googlegroups.com...
> Hi,
> I can't get the simple batch below to run from the scheduler via right-
> click/Run. (Nor does it work if I schedule it to run).
>
> When I run it from Explorer or cmd window it works fine.
> I am running it w/ an administrator account and password (but have
> tried other accounts)
>
> Batch file contains the following single line:
> echo %date% %time% >> Test.txt
>
> I can see the black cmd window 'flash' so it appears to run, but does
> not write to the file.
> The batch and output file (Test.txt) live within the MyDocument folder
> of the user running the batch.
>
> Test.txt should contain (and does when run manually):
> Thu 05/22/2008 17:58:08.98 moormansd
> Thu 05/22/2008 17:59:01.28 moormansd
> etc.
>
> Scheduler shows exit status of 1 and a correct "Last Run Time"
>
> The Advanced/View Log shows:
> "Schedule Test.job" (ScheduleTest.bat)
> Started 5/22/2008 5:54:36 PM
> "Schedule Test.job" (ScheduleTest.bat)
> Finished 5/22/2008 5:54:36 PM
> Result: The task completed with an exit code of (1).
>
> What am I doing wrong!
> Thanks


In the line of code
echo %date% %time% >> Test.txt
you neither specify the drive nor the folder where
Test.txt should reside. It could be on any disk in any
directory! It is most probably in c:\windows\system32,
which you can easily verify by looking at the date stamp
of the file you're currently examining.

If you want to write robust batch files then you should
always fully specify your file names by quoting drive
letters and folder names.
 
Thanks.
In the interest of clarity I had edited the batch I posted. Below is
the one I have been using and it runs w/ the anomaly described above.
Summary: Runs correctly from Explorer, but does not run from
scheduler.

Just in case I search the entire drive for the file w/ no luck.

echo %date% %time% %UserName% >> "C:\Documents and Settings
\Administrator\My Documents\Computers\Batch & Shortcuts
\ScheduleTest.txt"
 
"livetohike" <moormansd@gmail.com> wrote in message
news:17b8183a-419e-4146-ad00-90b312fa4880@26g2000hsk.googlegroups.com...
> Thanks.
> In the interest of clarity I had edited the batch I posted. Below is
> the one I have been using and it runs w/ the anomaly described above.
> Summary: Runs correctly from Explorer, but does not run from
> scheduler.
>
> Just in case I search the entire drive for the file w/ no luck.
>
> echo %date% %time% %UserName% >> "C:\Documents and Settings
> \Administrator\My Documents\Computers\Batch & Shortcuts
> \ScheduleTest.txt"


I suggest you start nice and simple like so, then expand the
batch file one item at a time:
@echo off
echo %date% %time% %UserName% >> C:\Test.txt
echo Pausing for 30 seconds . . .
ping localhost -n 30 > nul
You must check the Task Scheduler's log file to see if
the task ran. And please don't wait another ten days with
your reply - this thread will have fallen off the edge of my
newsreader by then!
 
On Jun 3, 3:24 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "livetohike" <moorma...@gmail.com> wrote in message
>
> news:17b8183a-419e-4146-ad00-90b312fa4880@26g2000hsk.googlegroups.com...
>
> > Thanks.
> > In the interest of clarity I had edited the batch I posted. Below is
> > the one I have been using and it runs w/ the anomaly described above.
> > Summary: Runs correctly from Explorer, but does not run from
> > scheduler.

>
> > Just in case I search the entire drive for the file w/ no luck.

>
> > echo %date% %time% %UserName% >> "C:\Documents and Settings
> > \Administrator\My Documents\Computers\Batch & Shortcuts
> > \ScheduleTest.txt"

>
> I suggest you start nice and simple like so, then expand the
> batch file one item at a time:
> @echo off
> echo %date% %time% %UserName% >> C:\Test.txt
> echo Pausing for 30 seconds . . .
> ping localhost -n 30 > nul
> You must check the Task Scheduler's log file to see if
> the task ran. And please don't wait another ten days with
> your reply - this thread will have fallen off the edge of my
> newsreader by then!


Great idea! Interesting results.

It worked as you wrote it. I then moved the bat into each of the
following folders and retested:
OK - C:\Documents and Settings\
OK - C:\Documents and Settings\Administrator\
OK - C:\Documents and Settings\Administrator\My Documents
OK - C:\Documents and Settings\Administrator\My Documents\Computers\
NO - C:\Documents and Settings\Administrator\My Documents\Computers
\Batch & Shortcuts\

I finally realized scheduler does not like the ampersand even though
the path is quoted... strange?

Easy enough to rename the folder, but I would like to now why '&' is
not supported by the schedular.
I tried 'escaping' it via && w/ no luck.

Thanks
 
"livetohike" <moormansd@gmail.com> wrote in message
news:26858e89-7ef7-43c2-bfeb-a325a96d0a74@e53g2000hsa.googlegroups.com...
> On Jun 3, 3:24 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>> "livetohike" <moorma...@gmail.com> wrote in message
>>
>> news:17b8183a-419e-4146-ad00-90b312fa4880@26g2000hsk.googlegroups.com...
>>
>> > Thanks.
>> > In the interest of clarity I had edited the batch I posted. Below is
>> > the one I have been using and it runs w/ the anomaly described above.
>> > Summary: Runs correctly from Explorer, but does not run from
>> > scheduler.

>>
>> > Just in case I search the entire drive for the file w/ no luck.

>>
>> > echo %date% %time% %UserName% >> "C:\Documents and Settings
>> > \Administrator\My Documents\Computers\Batch & Shortcuts
>> > \ScheduleTest.txt"

>>
>> I suggest you start nice and simple like so, then expand the
>> batch file one item at a time:
>> @echo off
>> echo %date% %time% %UserName% >> C:\Test.txt
>> echo Pausing for 30 seconds . . .
>> ping localhost -n 30 > nul
>> You must check the Task Scheduler's log file to see if
>> the task ran. And please don't wait another ten days with
>> your reply - this thread will have fallen off the edge of my
>> newsreader by then!

>
> Great idea! Interesting results.
>
> It worked as you wrote it. I then moved the bat into each of the
> following folders and retested:
> OK - C:\Documents and Settings\
> OK - C:\Documents and Settings\Administrator\
> OK - C:\Documents and Settings\Administrator\My Documents
> OK - C:\Documents and Settings\Administrator\My Documents\Computers\
> NO - C:\Documents and Settings\Administrator\My Documents\Computers
> \Batch & Shortcuts\
>
> I finally realized scheduler does not like the ampersand even though
> the path is quoted... strange?
>
> Easy enough to rename the folder, but I would like to now why '&' is
> not supported by the schedular.
> I tried 'escaping' it via && w/ no luck.
>
> Thanks


Try escaping it like so: \Batch ^& Shortcuts\

About trouble-shooting: I don't claim any credit for having suggested
this approach. When attempting to solve a seemingly unsolveable
problem then it's standard practice
a) To break the problem into smaller and smaller pieces until
the cause becomes obvious, and
b) To simplify things as much as possible in order not to trip
over some issue that is hard to spot in complex code.
In the initial post in this thread you applied option b) (which
was a good thing) but you did it so savagely that it became
impossible for respondents to see the cause of the problem . . .
 
Back
Top