lua-users home
lua-l archive

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


Hello Rici,

Monday, March 5, 2007, 7:22:31 AM, you wrote:

RL> Of course, as you say, that won't redirect os.execute(). (Does
RL> standard C guarantee that changes to stdin, stdout and stderr
RL> be reflected in the command processor used by system()? Does
RL> Posix even guarantee that?)

I don't know, and to be honest, I don't care, as I'm on Windows :D And
up  until  now it worked just fine as long as the external application
didn't open a new console, on which I had no control whatsoever.

RL> In any event, if you want to freopen stdin (and friends),
RL> I suggest you just do that. There's no point creating a new
RL> Lua "file" object; once stdin is redirected, io.stdin will
RL> be automatically redirected. (If it isn't, then the redirection
RL> of print() won't work either.)

>From  my  tests,  it's  not. io.std* will still direct to the old file
descriptor,  which  is  now  invalid  (freopen closes the old stream).
That's  why I have the line "io.stdout=..." in the test script. But it
just  dawned  on  me you are right - I don't need to create a new file
object, I could just change the file descriptor in the existing one. I
don't know what I was thinking...

RL> I think your program is crashing on exit because the userdata
RL> you create (unnecessarily, I believe, as above) doesn't have
RL> the correct environment table, so it crashes when the __gc
RL> metamethod tries to close the stream.

That  was  my  guess,  as the code doing this is just copy-pasted from
liolib.c  (and  it's also the reason why I didn't try to automagically
set io.std* after redirecting them).

RL> My guess as to why you are not getting any output is that
RL> whatever filesystem you are using does not fsync() files
RL> on every write(). So even though it's not buffered by the
RL> C library, the internal buffers are not committed to disk.
RL> That's just a guess, though.

NTFS;  couldn't  really tell you which version precisely, I lost track
of them, so... It's the one in XP SP2. :)

Ok, so I'll do more reading on this again then try my hand at it again
and come back with the result, if anyone's interested in it.

-- 
Theodor-Iulian Ciobanu
Virus Researcher

e-mail: tciobanu@bitdefender.com

-----------------------------------------
Secure your every bit
-----------------------------------------