Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How execute sh command using Shake

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?

like image 487
mb14 Avatar asked Jul 22 '14 15:07

mb14


1 Answers

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.

like image 147
Neil Mitchell Avatar answered Nov 18 '22 12:11

Neil Mitchell