*! version 1.0 10sep2015

Title

windowsmonitor -- Send a winexec command to a Windows operating system and display the output in the Stata results window in (almost) real time

Syntax

windowsmonitor
[, options]

Main
command(string) the Windows command

winlogfile(filename) text file that will act as a temporary log of Windows output

waitsecs(integer) how long to wait for output before giving up

by, if, in and fweights are not allowed (nor are they relevant).

Description

Windows unfortunately does not stream the outputs from command-line activity (technically, the stdout and stderr streams) in such a way that they can appear inside Stata.
When running a winexec command, Stata waits for the process launched by the command to terminate before proceeding, and only then will all the output appear inside Stata.
If the command is time-consuming (such as calling CmdStan, which was the inspiration for this), not seeing progress can cause worry, or a waste of time, or undetected problems.
windowsmonitor is a work-around for this problem, which pipes the output to a text file, checks that file every 2 seconds and displays anything new in it.

Options

Main

command the Windows command, which will be invisibly augmented with the details to pipe output to winlogfile

winlogfile file (and path, if desired) to store the output in; by default a Stata tempfile will be used, so there is nothing to be gained from specifying a tempfile macro here

waitsecs number of seconds to wait for the first output before giving up

Remarks

The winlogfile will contain a line:

Finished!

once the command finishes, and it is this line that will signal to windowsmonitor to hand control back to Stata. If your Windows command will write "Finished!" to the screen for some reason, that will cause early handing back (or some other problem).

It is possible that there may be some contention for access to the winlogfile, although despite serious use on different project, computers and Windows versions, it has never happened yet.

Examples

. windowsmonitor, command("ping 127.0.0.1 -n 30")

. winexec ping 127.0.0.1 -n 30