How to use stdin/stdout redirect in Visual Studio Code task?

Viewed 4190

I'd like to compile my Stylus files with a Visual Studio Code task, but the command requires stdin/stdout redirection (with < and >):

stylus --compress < main.styl > main.css

This doesn't work as the behavior seems different from the shell.

Try

{
    "version": "0.1.0",
    "tasks": [
        {
            "taskName": "styles",
            "isBuildCommand": true,
            "isShellCommand": true,
            "echoCommand": true,
            "command": "stylus",
            "args": [
                "--compress",
                "<",
                "main.styl",
                ">",
                "main.css"
            ]
        }
    ]
}

Catch

running command$ stylus --compress < main.styl > main.css
/usr/local/lib/node_modules/stylus/bin/stylus:641
    if (err) throw err;
             ^

Error: ENOENT: no such file or directory, stat '<'
1 Answers

As far as I know, there is no way to redirect stdin and stdout from the task schema described here.

To do the redirection you will need to write a small utility that accepts the name of the executable, the input file, the output file and any other parameter. This utility EXE file will then execute your "stylus", redirect its input and output to the files specified on the utility executable. If your utility EXE file is called redirect.exe, your command line will be

redirect.exe stylus.exe main.styl main.css --compress

And your tasks.json will look like the following:

…
"command": "redirect.exe",
"args": [
    "stylus.exe", "main.styl", "main.css", "--compress", "--etc"
]
Related