<i>exec does not handle encoding</i> status still Open with 3 other changes
by
.
D 2023-11-27T16:47:26.819
J icomment The\s`exec`\scommand\sis\snotably\svery\ssimple-minded\sin\sthat\sit\suses\sthe\ssystem\sencoding\sfor\severything\sincluding\sfor\sthe\sencoding\sof\schannels\sused\sto\scommunicate\swith\sthe\ssubprocess,\sand\sit\salways\sassumes\sthat\soutput\sis\sreadable\stext\sin\sthat\sencoding.\s*It\svery\smuch\sis\sknown\sthat\sthis\sisn't\salways\sso!*\sHowever,\s"fixing"\sthis\stends\sto\smake\s`exec`\smuch\sharder\sto\suse\sin\sthe\ssimple\scases.\r\n\r\nThe\s***workaround***\sis\sto\suse\sa\spipeline,\sperhaps\slike\sthis:\r\n```\r\n\s\sset\sf\s[open\s|$cmd\srb]\r\n\s\s#\sBinary\soutput\scan\sbe\sany\sbyte\ssequence;\sno\sencoding\sproblems\spossible\r\n\s\sset\soutput\s[read\s$f]\r\n\s\scatch\s{close\s$f}\serr\r\n```\r\nSince\syou\shave\saccess\sto\sthe\schannel\sabove\s(unlike\sinside\s`exec`\swhich\shandles\sall\sof\sthat\sinternally)\syou\scan\sconfigure\sit\sany\sway\syou\swant\sto\shandle\sthe\sinput\sor\soutput\syou\sexpect.\s(It\salso\smakes\sit\seasier\sto\scapture\sstderr\sof\sthe\spipeline\swithout\slosing\sstdout,\setc.)\r\n\r\nNote\sthat\sboth\s`exec`\sand\s`open\s|...`\sare\swrappers\saround\sthe\ssame\ssubsystem.
J login dkf
J mimetype text/x-markdown
K 0f1ddc0df7fb734cf1cba12ac7c529d29fefb842
U dkf
Z 02cde42f09ded1ee209613568755e2cb