taskrun

set up standard input for command, run command, and save output 

Command


SYNOPSIS

taskrun [-ae] [-c calling_command] [-l logfile] [-M mail_command] [-m user] command [input...]


DESCRIPTION

The taskrun utility sets up the standard input for the specified command, runs the command, and places the output of that command in a user-specified location. taskrun was designed primarily for use with at, batch, and wts so that output and errors produced by tasks scheduled with these utilities could be provided to whoever scheduled them.

If the command specified on the taskrun command line has a file association then that is used when creating the command string which is passed to CreateProcess() to be executed. If there is no file association, or if the environment variable TK_DO_NOT_RUN_WITH_REG_ASSOCIATIONS is set, then the command specified on the taskrun command line is the command string which is passed to CreateProcess() to be executed.

The input arguments specified on the command line are used as the standard input for command, with each argument being treated as one line of input.

On 8.1/2012R2/10/2016/2019/11/2022, errors produced while running taskrun are written to the Event Log.

All log files used by taskrun are locked so that only one instance of taskrun can write to a particular log file at a particular time. They are not locked to prevent users from edit them. This means that it is possible for you to be editing a log file when taskrun attempts to append to it and thus, lose the appended material. For this reason, you should be very careful when editing log files.

Note:

When the specified command is a DOS (16-bit) utility, anything written to the standard error is not redirected.

Normally, when a scheduled task is run, an empty console window is displayed. To prevent this display, you must do the following:

Options

-a 

lets the user know that the command successfully executed if one or more of -e, -l, or -m are specified and the command successfully executed without producing any output.

-c calling_command 

specifies the command that called taskrun. If this option is not specified, calling_command defaults to taskrun.

-e 

is only valid on 8.1/2012R2/10/2016/2019/11/2022 and writes any output or errors produced to the Event Log. If -a is also specified and no output or errors are produced, a message indicating that the command executed successfully is written to the Event Log.

Note:

Each Event Log entry added by taskrun is limited to a length of 8192 bytes. If you are expecting more than 8192 bytes of output, you should also use -l or -m to ensure that all output is captured.

The Event Source for these messages is the calling_command.

Note:

If you want your Event Log messages to be properly formatted, you should do the equivalent of the following for every calling_command:

registry -s \
  -k 'HKLM\System\CurrentControlSet\Services\EventLog\Application\calling_command' \
  -n EventMessageFile -V 'str:c:\winnt\system32\mksmsg.dll'
registry -s \
  -k 'HKLM\System\CurrentControlSet\Services\EventLog\Application\calling_command' \
  -n TypesSupported -V dword:0x7 

-l logfile 

appends any output or errors produced to the specified logfile. If -a is also specified and no output or errors are produced, a message indicating that the command executed successfully is written to logfile.

-M mail_command 

when sending e-mail, taskrun uses the command specified by mail_command to actually send the e-mail. The specified mail_command must accept the following option syntax:

-f from_address -m file_to_be_mailed -s subject to_address

The specified mail_command can be a MKS KornShell script; however, in that case, the specified script name must have either a .ksh or .sh extension.

When this option is not given, taskrun uses the MKS Toolkit smtpmail command to send e-mail.

-m user 

uses smtpmail to e-mail the output and errors produced by the command to the specified user. If no output or errors are produced, no e-mail is sent, unless -a is also specified, in which case, an e-mail indicating that the command executed successfully is sent to user.

The calling_command is used as the from line for all e-mail messages sent. The first word of command is used as the subject line.

Note:

When taskrun sends e-mail using smtpmail, the Date: fields are set by the system that runs the task. The Received date is setup by the SMTP Mail server, and if the time is set differently on the two systems, discrepancies may appear in the e-mail you receive. For example, if the SMTP Mail server's time is slightly behind that of the system that ran the task, it could appear that you received the e-mailed output from the task before it was run.


EXAMPLES

The command:

taskrun -e -c at cat 1 2 3

results in the following message being added to the Event Log for at:

Date: 20010911091402
Command: cat
Input:
        1
        2
        3
ExitCode: 0

1
2
3

ENVIRONMENT VARIABLES

TK_DO_NOT_RUN_WITH_REG_ASSOCIATIONS 

When this variable is set, file associations are not used when creating the command string passed to the CreateProcess() for execution.

TK_UNIX_FILESYSTEM 

When this variable is set, the Enhanced UNIX Compatibility Mode is on and the virtual file system is in use.

When the Enhanced UNIX Compatibility Mode is on, all path names in the commands that you schedule should be Windows path names. In addition, information about a scheduled job (such as the working directory) is displayed using Windows path names.

For details on the Enhanced UNIX Compatibility Mode and the virtual file system, see the EUCM reference page.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred.


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


AVAILABILITY

PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
assoc, at, ftype, smtpmail

MKS Toolkit Scheduling Solutions Guide


PTC MKS Toolkit 10.4 Documentation Build 39.