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?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Rodrigo Ribeiro
  • 3,198
  • 1
  • 18
  • 26

2 Answers2

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)
Sibi
  • 47,472
  • 16
  • 95
  • 163
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"
lukad
  • 17,287
  • 3
  • 36
  • 53