Schedular just won't work

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
 
P

Pegasus \(MVP\)

livetohike said:
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.
 
L

livetohike

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"
 
P

Pegasus \(MVP\)

livetohike said:
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!
 
L

livetohike

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
 
P

Pegasus \(MVP\)

livetohike said:
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 . . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top