Using the scheduled tasks in cmd mode

F

Francis Perron

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.

Any ideas on that would be greatly appreciated.

Thanks
 
I

Ismael

Francis, in Windows NT/2000 the dos command to schedule a
task is at. If you type at ? you should be able to see
the switches you can use. You may have to redirect the
output of the the command you wish to schedule to a file.
The redirect symbol is >. For example, if you would like
to redirec the output of dir to a file called dir.txt the
command will be dir > dir.txt

Hope this helps.

Ismael
 
M

Michael Bednarek

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>.
 
N

Ndi

I don't understand your scheduled command: why invoke CMD.EXE to run
COMMAND.COM ?

It invokes command.EXE as I see. Which seems to be a 3rd party exe. Also,
I think it must be third party as I remember no command having a /o:log as
valid input ...
 
M

Michael Bednarek

It invokes command.EXE as I see. Which seems to be a 3rd party exe. Also,
I think it must be third party as I remember no command having a /o:log as
valid input ...

Yes, you're right. I didn't read closely enough. However, I can't
believe any third party would be so daring and name a program
"COMMAND.EXE".

But I suspect the OP didn't present his environment as precisely as we
would like - a common occurrence.
 
M

Mark V

In said:
Yes, you're right. I didn't read closely enough. However, I can't
believe any third party would be so daring and name a program
"COMMAND.EXE".

But I suspect the OP didn't present his environment as precisely
as we would like - a common occurrence.

Yes, I thought that the OP meant:
cmd.exe /c "<command> /o:log"
when he wrote
cmd.exe /c "C:/command.exe /o:log"
 
M

Mark V

In said:
Francis, in Windows NT/2000 the dos command to schedule a
task is at. If you type at ? you should be able to see
the switches you can use. You may have to redirect the
output of the the command you wish to schedule to a file.
The redirect symbol is >. For example, if you would like
to redirec the output of dir to a file called dir.txt the
command will be dir > dir.txt

OP may want to aquire JT.EXE to use instead of AT.EXE

http://www.jsiinc.com/SUBF/TIP2600/rh2621.htm
ftp://ftp.microsoft.com/reskit/win2000/jt.zip
 

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