Statalist


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

Re: st: True batch mode


From   "Russell V. Lenth" <[email protected]>
To   [email protected]
Subject   Re: st: True batch mode
Date   Wed, 09 Apr 2008 21:39:17 -0500

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/



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