Quoth Jason Dusek <[email protected]>,
> Using `System.Process.runInteractiveProcess', I can start a process
> and get a handle to it:
>
> runInteractiveProcess
> :: FilePath
> -> [String]
> -> Maybe FilePath
> -> Maybe [(String, String)]
> -> IO (Handle, Handle, Handle, ProcessHandle)
>
> For diagnostic purposes, I'd like to print the PID of the
> process attached to this handle -- how best to do that?
There's a good chance this isn't the best way, but it seems to work:
import System.Process
import System.Process.Internals (ProcessHandle__(..), PHANDLE,
withProcessHandle)
-- for use with withProcessHandle
getPID :: ProcessHandle__ -> IO (ProcessHandle__, Maybe PHANDLE)
getPID h@(OpenHandle t) = return (h, Just t)
getPID h@(ClosedHandle t) = return (h, Nothing)
main = do
(h0, h1, h2, hp) <- runInteractiveProcess "/bin/date" [] Nothing Nothing
mp <- withProcessHandle hp $ getPID
print mp
Seems like more scaffolding than this application really ought to require.
Donn
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe