Statalist The Stata Listserver


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

Re: st: -winexec- and log files


From   Alan Riley <[email protected]>
To   [email protected]
Subject   Re: st: -winexec- and log files
Date   Thu, 7 Dec 2006 16:21:21 -0600

Zurab Sajaia ([email protected]) asked about a closed log
file remaining locked after another process has been started
by Stata witn -winexec-.  I will include his original email
below my reply.

This is a side-effect of the way in which -winexec- is starting
the new process.  We can change the behavior, so we will in a
future executable update.

If you are interested in low-level specifics of programming in
C under Microsoft Windows, continue reading.

-winexec- uses the Microsoft SDK function CreateProcess()

  http://msdn.microsoft.com/library/en-us/dllproc/base/createprocess.asp
  <http://msdn.microsoft.com/library/en-us/dllproc/base/createprocess.asp>

to launch an external application.  One of the parameters passed
to CreateProcess() is 'bInheritHandles' which specifies whether
the newly launched application (in Zurab's case, Notepad) should
inherit the file handles from the calling application (Stata).
We are passing this parameter as TRUE, which means that even
if Zurab closes the log file and -exit-s Stata after launching
Notepad, Notepad keeps an open copy of that file handle which
prevents Stata and other applications from erasing it.

We can change this parameter to FALSE so that any application
launched from Stata will not inherit these file handles, solving
Zurab's problem.


Alan
([email protected])

Zurab's original email:
> > I noticed strange behavior of Stata while using -winexec- and was wondering 
> > whether anyone has an explanation (including the one that nothing is 
> > strange here):
> > 
> > . log using c:\ttt, replace
> ---------------------------------------------------
>       log:  c:\ttt.smcl
>  log type:  smcl
> opened on:   6 Dec 2006, 18:48:11
> 
> . winexec notepad
> 
> . log close
>       log:  c:\ttt.smcl
>  log type:  smcl
> closed on:   6 Dec 2006, 18:48:15
> ---------------------------------------------------
> 
> . log using c:\ttt, replace
> file c:\ttt.smcl cannot be modified or erased; likely cause is read-only 
> directory or file
> r(608);
> 
> so if -winexec- was called while log was on, the log file stays locked 
> until the program that -winexec- called is not terminated. Once you close 
> that window (notepad in our case) log file becomes writeable.  And log file 
> remains locked even if you exit the Stata.
<end>
*
*   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