Problem with Windows io.popen

From: steve donovan <steve.j.dono....at.gmail.com>
Date: Fri, 6 May 2011 13:12:36 +0200

Hi all,

io.popen inherits the limitations of the system popen and for Windows
GUI-mode applications that basically means 'broken'.

For instance, if you run a Lua script and it throws an error, the
standard error is not caught properly.

An ugly work-around is to redefine io.popen like this:

function io.popen(cmd)
  local tmp = os.getenv('APPDATA')..os.tmpname() -- important to get
a temp file in a write-able directory
  cmd = cmd:gsub('%S+$','') -- get rid of 2>&1
  os.execute(cmd..' 1> "'..tmp..'" 2>&1')
  return io.open(tmp,'r')
end

Note how the '2>&1' needs to be _after_ the redirection (don't ask me
why things have to be different!)

Either way, you get the dreaded black-box flashing; again, this is
more Windows nonsense.

I've got C code somewhere for a more well-behaved popen on Windows
which doesn't behave badly in this way[1], but in the meantime, you
can pop this into your customizations.

I now get a stack trace. However, double-clicking on the stack trace
in the error window does not do what I expect; TA opens the Lua file
in the view previously occupied by the error buffer and brings up a
tooltip. I would at least expect that it would go to the existing
view containing the source. (This happens on both sides of the OS
fence)

steve d.

[1] it also provides a way to get a genuine two-way process capture,
so things like capturing GDB become possible.
Received on Fri 06 May 2011 - 07:12:36 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 12:06:26 EST