Hello,
I want to know how you can get a dos command to be a
scheduled task. But I also want that command's logs to be
outputted too with some options of the command.
I tried to put the command like that:
cmd.exe /c "C:/command.exe /o:log"
But it does not output anything...And I have no clue if
it actually runs.
To determine whether your scheduled jobs runs or not, cause it to create
a file; the line:
ECHO This is %0% on %DATE% at %TIME% > fubar.log
should prove it. Put the above in a batch file, say C:\BAT\FUBAR.CMD,
and invoke it like: "CMD /C C:\BAT\FUBAR.CMD".
I don't understand your scheduled command: why invoke CMD.EXE to run
COMMAND.COM ?
I don't think CMD.EXE or COMMAND.COM do provide for a switch "/o:" to
produce a log file. It might be possible to slap a global redirection
directive on the whole job, like: "CMD /C C:\BAT\FUBAR.CMD >FUBAR.LOG",
but even if that works it will only log the output of commands, not
the commands themselves.
Here's the skeleton I use a lot for scheduled batch files. It uses
4NT.EXE (JPSoft) which does, among other things, provide a method
to create log files, unsurprisingly with the command "LOG".
----------------------------------------------------------------------
:: Construct a logfile name and turn logging on
Set me=%@Name[%_BATCHNAME]
Set mePath=%@Path[%@SFN[%_BATCHNAME]]
:: Construct "today" as "YYMMDDhhmmss"
Set today=%@Right[2,%_Year]%@Format[02,%_Month]%@Format[02,%_Day]%@Format[02,%_Hour]%@Format[02,%_Minute]%@Format[02,%_Second]
Set Logfile=%[mePath]%[me]-%[today].log
Log /W %LogFile
:: Body of the batch file
:: Delete log files older than 7 days
DEL /[d-7,1/1/80] /E %[mePath]%[me]-????????????.log >>& %LogFile
LOG OFF
QUIT 0
----------------------------------------------------------------------
The log file shows a date/time stamped line for each executed command,
and you can redirect the output of individual commands into that log
as well (see the DEL command above).
4NT is documented at <
http://jpsoft.com/help/>, LOG is documented at
<
http://jpsoft.com/help/log.htm>.