[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Redirecting stdin/stdout/stderr in embedded environment
- From: "Mark Edgar" <medgar123@...>
- Date: Thu, 19 Apr 2007 09:48:49 -0700
Does your application change these standard handles just once, at its
startup and before it initializes Lua? If so, one solution would be
for your application to modify the standard handles, and then "exec"
itself. Then, stdin/out/err would be setup as CreateProcess says.
If you can't do this, then you can use _fdopen and make use of the
fact that MSVCRT seems to reuse standard FILE slots:
HANDLE h = CreateFooHandle(yadda, yadda, yadda);
FILE *f = _fdopen(_open_osfhandle((long)h, _RD_ONLY), "rb");
assert( f == stdin ); /* hopefully! */
/* rinse, repeat for stdout, stderr */
Yes, this is a dirty, ugly hack. Please clearly mark it as such in