Re[2]: [Haskell-cafe] Execution of external command

Hello gwern0, Thursday, December 13, 2007, 4:43:02 PM, you wrote:
to get at stdout. I don't think this would go through cmd/sh, but honestly, specifying a particular interpreter breaks your portability anyway
these scripts will be written by users so they don't need to be the same for win&unix. i guess that users will prefer to use perl or something like this for these scripts and afaiu in both windows and linux this need to go through sh/cmd it seems that script may be not terminated if its output isn't read, so better code should be (_, h, g, _) <- runInteractiveCommand "script params" result <- hGetLine h hGetContents h >>= evaluate.length hGetContents g >>= evaluate.length am i right? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

it seems that script may be not terminated if its output isn't read, so better code should be
(_, h, g, _) <- runInteractiveCommand "script params" result <- hGetLine h hGetContents h >>= evaluate.length hGetContents g >>= evaluate.length
Tangent here, but does anyone else think that something like hGetContentsEagerly would be handy in System.IO? When I am reading lots of little files I worry about open file limits. And besides, it seems like unsafeInterleaveIO can result in IO exceptions coming from pure code, so why use it if you don't have to?

qdunkan:
it seems that script may be not terminated if its output isn't read, so better code should be
(_, h, g, _) <- runInteractiveCommand "script params" result <- hGetLine h hGetContents h >>= evaluate.length hGetContents g >>= evaluate.length
Tangent here, but does anyone else think that something like hGetContentsEagerly would be handy in System.IO? When I am reading lots of little files I worry about open file limits. And besides, it seems like unsafeInterleaveIO can result in IO exceptions coming from pure code, so why use it if you don't have to?
I'll put a System.IO.Strict up on the weekend. Until then, perhaps use, as I sometimes do: import qualified Data.ByteString as S hGetContentsStrict = S.unpack `fmap` S.hGetContents Cheers, Don

Evan Laforge wrote:
it seems that script may be not terminated if its output isn't read, so better code should be
(_, h, g, _) <- runInteractiveCommand "script params" result <- hGetLine h hGetContents h >>= evaluate.length hGetContents g >>= evaluate.length
Tangent here, but does anyone else think that something like hGetContentsEagerly would be handy in System.IO?
YES! Jules PS we could give it a nice sensible name like hGetContents. We could renaming the existing hGetContents to hUnsafeGetContentsDontUseThisUnlessYouHaveSpentThreeMonthsLearningGHCsExecutionSemanticsOrYouWillRegretIt

Hello Jules, Friday, December 14, 2007, 12:21:30 PM, you wrote:
PS we could give it a nice sensible name like hGetContents. We could renaming the existing hGetContents to hUnsafeGetContentsDontUseThisUnlessYouHaveSpentThreeMonthsLearningGHCsExecutionSemanticsOrYouWillRegretIt
i have more advanced proposal - we should include in its name whole paper on its semantics so anyone using it will be clearly warned. moreover, any suggestion to use this function will automatically include exact description of its caveats that is again The Right Thing To Do :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Dec 14, 2007 10:38 AM, Bulat Ziganshin
hUnsafeGetContentsDontUseThisUnlessYouHaveSpentThreeMonthsLearningGHCsExecutionSemanticsOrYouWillRegretIt
i have more advanced proposal - we should include in its name whole paper on its semantics so anyone using it will be clearly warned. moreover, any suggestion to use this function will automatically include exact description of its caveats that is again The Right Thing To Do :)
Until, that is, the first library appears on Hackage that aliases the name to ohBugger :-) - Benja

On 14 Dec 2007, at 1:21 AM, Jules Bean wrote:
Evan Laforge wrote:
it seems that script may be not terminated if its output isn't read, so better code should be
(_, h, g, _) <- runInteractiveCommand "script params" result <- hGetLine h hGetContents h >>= evaluate.length hGetContents g >>= evaluate.length Tangent here, but does anyone else think that something like hGetContentsEagerly would be handy in System.IO?
YES!
Jules
PS we could give it a nice sensible name like hGetContents. We could renaming the existing hGetContents to hUnsafeGetContentsDontUseThisUnlessYouHaveSpentThreeMonthsLearningGHCs ExecutionSemanticsOrYouWillRegretIt
On the contrary, it's great for writing filters. OTOH, using the result of hGetContents interleaved with other IO actions feels like a reversion to the bad old days of dialogs (which it is, of course). jcc
participants (6)
-
Benja Fallenstein
-
Bulat Ziganshin
-
Don Stewart
-
Evan Laforge
-
Jonathan Cast
-
Jules Bean