[Haskell-cafe] Re: Return value of a (windows) process

Tim trbauer at gmail.com
Wed Oct 20 14:46:17 EDT 2010


I have never used the above function you refer to so I am not sure
about it's semantics. However, I have successfully used functions in
System.Process module [1] (fairly standard) to spawn processes and get
their exit codes on Windows.

For example, (javac exits code 2 when provided no arguments)

C:\Documents and Settings\Tim>javac
Usage: javac <options> <source files>
where possible options include:
 -g                         Generate all debugging info
 ... snip

C:\Documents and Settings\Tim>echo %ERRORLEVEL%
2

C:\Documents and Settings\Tim>ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m System.Process
Prelude System.Process> readProcessWithExitCode "c:\\jdk6\\bin\
\javac.exe" [] ""
(ExitFailure 2,"","Usage: javac <options> <so...

Hope this helps.
- Tim

[1] System.Process http://haskell.org/ghc/docs/6.12.2/html/libraries/process-1.0.1.2/System-Process.html

On Oct 19, 10:12 pm, Arnaud Bailly <arnaud.oq... at gmail.com> wrote:
> Hello,
> I have the following code (fragment) I use to wrap execution of
> various processes in Haskell, in the spirit of Don Stewart's slides
> about "Scripting in Haskell".
>
> instance MonadExec IO where
>   exec proc args = do (exit, out, err) <-  liftIO $
> readProcessWithExitCode proc args ""
>                       case exit of
>                         ExitFailure e -> throwError $ userError ("Fail
> execution of " ++ program proc args ++ ": " ++ (show e) ++", " ++err)
>                         ExitSuccess   -> return out
>
> Here is the abridged declaration of MonadExec:
> class (Monad m) => MonadExec m  where
>   exec      :: String -> [String] -> m String
>
> The issue I am facing is that readProcessWithExitCode does not seem to
> return the expected failures.
> When I run some failing process within windows command shell, I have:
>
> D:\projets\psug-dojo\lags>"d:/Program
> Files/scala-2.8.0/bin/scalac.bat" -d target\test-classes -classpath
> target\classes;D:\projets\
> psug-dojo\lags\test-lib\specs_2.8.0-1.6.5.jar;D:\projets\psug-dojo\lags\test-lib\scalacheck_2.8.0-1.7.jar;D:\projets\psug-dojo\lags\
> test-lib\junit-4.7.jar -d target\test-classes
> src\test\scala\oqube\lags\LagsTest.scala
> src\test\scala\oqube\lags\LagsTest.scala:86: error: not found: value beS_==
>       bid.sublists(List(Request(1,2,3))) must
> beS_==(List(Nil,List(Request(1,2,3))))
>                                               ^
> one error found
>
> D:\projets\psug-dojo\lags>echo %ERRORLEVEL%
> 1
>
> D:\projets\psug-dojo\lags>
>
> but wrapping this same process in my "shell", I always got an ExitSuccess.
>
> What am I doing wrong ?
>
> Thanks
> Arnaud
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list