[Haskell-cafe] Re: how to pipe in pure input with HSH? (Would be
helpful for sending emails via sendmail/mailx via HSH interface)
John Goerzen
jgoerzen at complete.org
Thu Dec 11 10:27:17 EST 2008
Thomas Hartman wrote:
> {-
> I am trying to figure out a way to send email using HSH and I'm stumped.
>
> The problem is that there is no ShellCommand instance for a pure
> vanilla string, which can be piped into another ShellCommand. There is
> a ShellCommand String instance, but the string is a command to be
> executed.
Hi Thomas,
See echo and echoBS here:
http://hackage.haskell.org/packages/archive/HSH/1.2.6/doc/html/HSH-ShellEquivs.html#v%3Aecho
-- John
>
> I defined PureInput wrapper around String in an attempt to get this
> working, but I'm stumped defining
> an fdInvoke method for it.
>
> class (Show a) => ShellCommand a where
> fdInvoke ::
> a
> -> System.Posix.Types.Fd
> -> System.Posix.Types.Fd
> -> [System.Posix.Types.Fd]
> -> IO ()
> -> IO [InvokeResult]
>
> Can someone help out? Below is a stub.
>
> Thomas.
> -}
>
> import HSH
>
> newtype PureInput = PureInput { unpureinput :: String }
> deriving (Read,Show)
>
>
> -- This works fine, blah blah blah gets outputted
> demo1 = runIO $ ( ( ( ("echo blah blah blah") :: String) -|- ( "cat"
> :: String) ) :: PipeCommand String String )
>
>
> -- This is what I want. Specify a pure input string, to be piped into
> another command.
> -- In this example it's cat, which isn't very usefuol.
> -- This would be useful, however, for sending email via sendmail or
> mailx, with variable input piped in.
> -- The result should be that "blah blah blah" is printed from cat,
> just as in demo1.
> demo2 = runIO $ (PureInput "blah blah blah") -|- ( "cat" :: String)
>
> -- How can/should this be done?
> instance ShellCommand PureInput where
> fdInvoke (PureInput justAString) ifd ofd closefd forkfunc = undefined
>
More information about the Haskell-Cafe
mailing list