I'm trying to migrate an existing makefile to Shake and so far I've tried the following (just create a file with the content of a directory)
module Main where
import Development.Shake
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_build"} $ do
let ls = "_build/ls.txt"
want [ls]
ls *> \out -> do
cmd "ls > " out
When I run it, I get the following error message :
> runghc test.hs _build/ls.txt
# ls (for _build/ls.txt)
ls: >: No such file or directory
ls: _build/ls.txt: No such file or directory
Error when running Shake build system:
* _build/ls.txt
Development.Shake.cmd, system command failed
Command: ls > _build/ls.txt
Exit code: 1
Stderr:
ls: >: No such file or directory
ls: _build/ls.txt: No such file or directory
What Am I doing wrong? How do you execute a sh
command and redirect its output?
To start with the conversion you probably want:
cmd Shell "ls >" out
The argument Shell
tells Shake to use the system shell, meaning the redirect works. Later on you may wish to switch to:
Stdout result <- cmd "ls"
writeFile' out result
Now you are not invoking the shell, but capturing the output with Shake. Sometime later, you may wish to switch to:
getDirectoryFiles "." ["*"]
Which is the Shake tracked way of getting a list of files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With