[Haskell-cafe] Re: Return value of a (windows) process
Arnaud Bailly
arnaud.oqube at gmail.com
Wed Oct 20 16:25:08 EDT 2010
Well, I must be doing something wrong but don't know where, the code
is rather straightforward.
Or the scalac.bat script is buggy:
Prelude Environment System.Process> readProcessWithExitCode
"d:/Program Files/scala-2.8.0/bin/scalac.bat" ["-d","target"] ""
(ExitSuccess,"","Exception in thread \"main\"
scala.tools.nsc.FatalError: target does not exist or is not a
directory\n\tat
scala.tools.nsc.settings.MutableSettings$OutputDirs.checkDir(MutableSettings.scala:227)\n\tat
scala.tools.nsc.settings.MutableSettings$OutputDirs.setSingleOutput(MutableSettings.scala:236)\n\tat
scala.tools.nsc.settings.MutableSettings$OutputSetting.value_$eq(MutableSettings.scala:452)\n\tat
scala.tools.nsc.settings.MutableSettings$OutputSetting.value_$eq(MutableSettings.scala:445)\n\tat
scala.tools.nsc.settings.MutableSettings$StringSetting.tryToSet(MutableSettings.scala:418)\n\tat
scala.tools.nsc.settings.MutableSettings$$anonfun$parseNormalArg$1$1$$anonfun$apply$3.apply(MutableSettings.scala:121)\n\tat
scala.tools.nsc.settings.MutableSettings$$anonfun$parseNormalArg$1$1$$anonfun$apply$3.apply(MutableSettings.scala:121)\n\tat
scala.tools.nsc.settings.MutableSettings.tryToSetIfExists$1(MutableSettings.scala:98)\n\tat
scala.tools.nsc.settings.MutableSettings.parseNormalArg$1(MutableSettings.scala:121)\n\tat
scala.tools.nsc.settings.MutableSettings.doArgs$1(MutableSettings.scala:154)\n\tat
scala.tools.nsc.settings.MutableSettings.parseParams(MutableSettings.scala:160)\n\tat
scala.tools.nsc.settings.MutableSettings.processArguments(MutableSettings.scala:44)\n\tat
scala.tools.nsc.CompilerCommand.processArguments(CompilerCommand.scala:87)\n\tat
scala.tools.nsc.CompilerCommand.<init>(CompilerCommand.scala:91)\n\tat
scala.tools.nsc.Main$.process(Main.scala:52)\n\tat
scala.tools.nsc.Main$.main(Main.scala:122)\n\tat
scala.tools.nsc.Main.main(Main.scala)\n")
Arnaud
On Wed, Oct 20, 2010 at 8:46 PM, Tim <trbauer at gmail.com> wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list