[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Tracing dofile execution

From   Eric Booth <>
Subject   Re: st: RE: Tracing dofile execution
Date   Tue, 9 Feb 2010 14:28:38 -0600

On Feb 9, 2010, at 2:16 PM, Martin Weiss wrote:

> <>
> To be honest, I cannot see what the -program- adds to Stata in terms of
> functionality - you can -trace- the execution of a do-file. I am sure I am
> overlooking something...

Also,  the -set trace- help file already includes options for modifying the depth and hiliting.

Anyways, to answer your question, this won't work in OSX.  
The copy command in OSX is "cp" and has different options than DOS's "/y /a".
(There is a "copy" command but it's not a file copy command, it's for kernal copying.))

The "cp" command doesnt append files together before the copy, as is the case in 
the DOS version of "copy".  There's probably other *nix commands to do this, but it might be a better
idea if you can write them all into the same file from Stata using -file write-.  Or you could add them together
first using something similar to "appendfile" (from SSC).
If you could get the OSX version of "cp" to do what you need, you could write a platform specific command 
for each OS, something like:

if "`c(os)'" == "Windows" {
!copy "`top'"+"`using'"+"`bottom'" "`c(sysdir_personal)'dotemp.ado" /y /a

if "`c(os)'" == "MacOSX" {
!cp  "`top'"+"`using'"+"`bottom'" "`c(sysdir_personal)'dotemp.ado" -R
*( you'd need to explore the help file for "cp" to see if it could append the files first)


Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754
Fax: +979.845.0249

> -----Original Message-----
> From:
> [] On Behalf Of David Elliott
> Sent: Dienstag, 9. Februar 2010 20:35
> To:
> Subject: st: Tracing dofile execution
> A frequent frustration I have is not being able to have -set trace on-
> trace the executing lines of a dofile.  I've seen some discussions on
> the list regarding this but no definitive solutions.  Michael Blasnik
> created a little -stepdo- utility to emulate the trace function but it
> chokes on //comment lines and multiline commands.  I decided to stop
> whining and write a little utility of my own.  Basically, it turns the
> dofile into a temporary adofile and then runs it under -set trace on-
> conditions that can be user modified for depth and hiliting.  The
> output is identical to an adofile trace because it IS an adofile
> during the run.
> x------------- begin code -------------x
> program define dodebug
> version 9.0
> *! version 1.0.1  2010.02.09
> *! Run a do-file with trace
> *! by David C. Elliott
> syntax using/ [, Depth(integer 1) Hilite(string)]
> capture program drop dotemp
> tempfile top bottom
> file open top using `"`top'"', write text
> file write top "program define dotemp" _n ///
>    "version 9" _n ///
>    `"noisily di "{res:{hline 10} begin debug {hline}}""' _n
> file close top
> file open bottom using `"`bottom'"', write text
> file write bottom _n "set trace off" _n "end" _n
> file close bottom
> !copy "`top'"+"`using'"+"`bottom'" "`c(sysdir_personal)'dotemp.ado" /y /a
> set trace on
> set tracedepth `depth'
> set tracehilite "`hilite'"
> dotemp
> set trace off
> noisily di "{res:{hline 10} end debug {hline}}"
> erase "`c(sysdir_personal)'dotemp.ado"
> end
> x------------- end code -------------x
> This runs fine under Windows but I have no way of testing in Mac or
> *nix environments so I don't know if the file appending shell command
> will work in all settings.
> I experimented with trying to -file write- above and below the
> existing text of a dofile without success leading me to apply the
> !copy kludge to wrap the dofile wolf in adofile sheep's clothing.  If
> someone can educate me how I could do this with -file write- in text
> mode, I'd be most grateful.
> Feedback would be appreciated and if there is a favorable response
> regarding usefulness I may whip up a helpfile and submit this to SSC.
> Regards,
> David Elliott MD, MSc
> *
> *   For searches and help try:
> *
> *
> *
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index