Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: True batch mode


From   "Sergiy Radyakin" <[email protected]>
To   [email protected]
Subject   Re: st: True batch mode
Date   Thu, 10 Apr 2008 10:10:43 -0400

Dear Russell,

I am glad that you have finally found a solution. I'd like to make a
couple of comments though:

1. it is normal documented and intended behaviour of capture to
suppress all output. I also agree that suppressing output and avoiding
error-stops in the program is two different tasks and call for two
different commands, rather than current all-or-nothing variant.

2. Stata program itself does not have a chance to affect the code flow
of the program that calls it. Windows allows the caller to decide
whether to wait or not for the program being called, but the program
being called may not halt the execution of the caller. This is being
regulated by the parameter llWaitForCompletion of CreateProcessEx,
which is called ultimately from any Windows program launching anything
else (program or process). Parameter /wait will ultimately determine
the value of llWaitForCompletion.

Best regards,
   Sergiy Radyakin

On 4/9/08, Russell V. Lenth <[email protected]> wrote:
> Sergiy,
>
> The problem with method 2. is that -capture- suppresses all output (why, I
> don't know).  I hope I don't have to resort to 3. or 4., just to get
> behavior that I should expect out-of-the-box.
>
> So I tried approach 1....
>
> ---- file stata.bat ----
> @echo off
>
> start "title needed" /w "c:\Program Files\Stata10\wstata.exe" /e do %1
>
> echo Exit code: %errorlevel%
> ---- end ----
>
> It "works" in a sense; however, the error code is 0 even if there is an
> error in the do file.  And if I try to trap errors in the do file using
> -capture-, I don't get any output when it runs correctly.
>
> This is ridiculous.  You shouldn't have to pull teeth to do this.  For batch
> processing, Stata should behave like everything else -- run in the
> foreground and return an appropriate exit code.  It's nice to have the
> OPTION of running in the background, but it shouldn't be shoved down your
> throat.
>
> Russ
> --
> Russell V. Lenth, Professor
> Department of Statistics
>  & Actuarial Science            (319)335-0814    FAX (319)335-3017
> The University of Iowa           [email protected]
> Iowa City, IA 52242  USA
> http://www.stat.uiowa.edu/~rlenth/
>
> Sergiy Radyakin wrote:
> > On 4/9/08, Russell V. Lenth <[email protected]> wrote:
> >
> > > When I try to run Stata in batch mode on Windows...
> > >
> > >       DOS> wstata /e do testfile.do
> > >
> > > ... it runs in the background, returning a new DOS prompt before the job
> is
> > > done.  That's fine if I'm doing it manually, but I want to run Stata as
> part
> > > of a process, and the next step needs Stata to be finished creating its
> > > output before it starts.  I suppose I could have Stata write some new
> file
> > > at the very end, but then if there's an error, that file will never get
> > > written.  Ideas?
> > >
> >
> >
> > Depends on the skill level:
> >
> > 1. start /w ........
> >    /w = /wait
> >
> > 2.
> >
> > DOS>delete file_marker
> > DOS> wstata /e do testfile.do
> >
> > // --- testfile.do ---
> >  capture do another.do  // capture will ensure we return back to write
> > the marker
> >  write file_marker
> > // --- end of testfile.do ---
> >
> > put your program into another.do
> >
> ---------------------------------------------------------------------------------------------------------
> >
> > 3. CreateProcessEx(lcExe,lcCommandLine,lcStartDirectory,;
> >
> lnShowWindow,llWaitForCompletion,lcStdOutputFilename)
> >
> > 4. ShellExecuteEx(LPSHELLEXECUTEINFO lpExecInfo);
> >
> > Both 3 and 4 are very similar and converge at one point to the same
> > thing. Which one to use is a matter of convenience.
> >
> ---------------------------------------------------------------------------------------------------------
> > 5. if none of the above is ok, I can suggest other variants
> >
> > Best regards, Sergiy Radyakin
> >
> >
> > > [BTW, the context here is Windows, version Stata/IC, but I need to
> extend to
> > > other platforms.  e.g., looks like maybe this isn't a problem on Linux
> --
> > > just don't put an ampersand?]
> > >
> > > Russ
> > > --
> > > Russell V. Lenth, Professor
> > > Department of Statistics
> > >  & Actuarial Science            (319)335-0814    FAX (319)335-3017
> > > The University of Iowa           [email protected]
> > > Iowa City, IA 52242  USA
> > > http://www.stat.uiowa.edu/~rlenth/
> > >
> > > *
> > > *   For searches and help try:
> > > *   http://www.stata.com/support/faqs/res/findit.html
> > > *   http://www.stata.com/support/statalist/faq
> > > *   http://www.ats.ucla.edu/stat/stata/
> > >
> > >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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