Skip to content

Commit

Permalink
fix stdin broken after error
Browse files Browse the repository at this point in the history
  • Loading branch information
yurenchen000 authored and fiatjaf committed Jul 9, 2023
1 parent 384b684 commit e8b0ca1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ function raw(jsonstring, filter, flags) {
outBuffer = []
errBuffer = []

// window.FS=FS
flags = flags || []
Module.callMain(flags.concat(filter))
Module.callMain(flags.concat(filter, '/dev/stdin')) // induce c main open it

// make sure closed & clean up fd
if(FS.streams[1]) FS.close(FS.streams[1])
if(FS.streams[2]) FS.close(FS.streams[2])
if(FS.streams[3]) FS.close(FS.streams[3])
if(FS.streams.length>3) FS.streams.pop()

// calling main closes stdout, so we reopen it here:
FS.streams[1] = FS.open('/dev/stdout', 577, 0)
Expand Down

0 comments on commit e8b0ca1

Please sign in to comment.