0

How could I capture compiler errors go in lua?

I'm trying to get the output of the comp compiler errors in a tmux panel using lua when executing the script the result is only shown in the current panel and not in the second panel and the /tmp/output file is always empty

cmd=io.popen("go build -gcflags=-e scree.go")
f=io.open("/tmp/output")
f:write(cmd:read("*all")) 
 for line in f:lines() do
    os.execute("tmux run-shell -t 2 'echo " .. line .. "' ")
 end 
f:close()

Is there any way to do this without using a temporary file?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
jhoss
  • 457
  • 3
  • 10
  • 19

1 Answers1

1

I'm not totally clear on this. But maybe something like the following. i.e. pipe stderr to stdout and capture the result (not tested).

f = assert (io.popen ("go build -gcflags=-e scree.go 2>&1")) 
 for line in f:lines() do
   os.execute("tmux run-shell -t 2 'echo " .. line .. "' ")
 end   
f:close()

I think the key is that popen won't capture stderr. See further details about that here

hookenz
  • 36,432
  • 45
  • 177
  • 286