11

I'm building a Haskell program that uses a command line argument parser using option-applicative library. Since I'm using stack to build and test my project, I would like to execute my program passing command line arguments using stack exec, like

stack exec myprogram-exe -i myfile.txt

but when I try to execute, Stack gives me the following message:

Usage: stack exec CMD [-- ARGS (e.g. stack ghc -- X.hs -o x)] ([--plain] |
              ([--ghc-package-path] | [--no-ghc-package-path])
              ([--stack-exe] | [--no-stack-exe]) [--package ARG])

Is there a way in which I can pass command line arguments to a program executed using Stack?

2
  • 1
    Try this stack exec -- myprogram-exe -i myfile.txt ?
    – Sibi
    Sep 9, 2015 at 15:00
  • @sibi that's the correct approach. Can you write it in as an answer? $(stack exec which foo) would also work on Unix shells Sep 9, 2015 at 17:19

2 Answers 2

17

Something like this should work:

stack exec -- myprogram-exe -i myfile.txt

Another way as Michael Snoyman says should be like this:

$(stack exec which foo)
1

You can also use stack build with the --exec flag to build and execute in one command. The arguments to the executable have to be included in the exec argument.

$ stack build --exec "myexecutable arg1 arg2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.