Trouble with hDuplicateTo before exec

Volker Wysk post at volker-wysk.de
Mon Jan 31 00:19:13 EST 2005


Hello.

"hDuplicateTo src tgt" overwrites the tgt handle with the src handle, but it 
doesn't overwrite the file descriptor used by tgt with that used by src. 
Rather, it makes a copy of src's fd and makes the overwritten tgt use that.

That's fine as long as we're in Haskell. But consider "hDuplicateTo h stdin". 
When calling executeFile afterwards, the replaced process expects its 
standard input on handle 0, not on the new fd generated by hDuplicateTo.

A workaround would be to use dupTo instead of hDuplicateTo, if we intend to 
call executeFile afterwards, but I have the case that this isn't known at the 
time. I'm forking a supplied IO action, connecting it with a pipe. The IO 
action may or may not call executeFile.

Regards,
V.W.



More information about the Glasgow-haskell-bugs mailing list