如何在 Visual Studio Code 任务中使用 stdin/stdout 重定向? [英] How to use stdin/stdout redirect in Visual Studio Code task?

查看:36
本文介绍了如何在 Visual Studio Code 任务中使用 stdin/stdout 重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Visual Studio Code 任务编译我的 Stylus 文件,但该命令需要 stdin/stdout 重定向(使用 <>):

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

这不起作用,因为行为似乎与 shell 不同.

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

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

捕捉

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 '<'

推荐答案

据我所知,没有办法从 这里.

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

要进行重定向,您需要编写一个小实用程序,它接受可执行文件的名称、输入文件、输出文件和任何其他参数.然后,该实用程序 EXE 文件将执行您的手写笔",将其输入和输出重定向到实用程序可执行文件上指定的文件.如果您的实用程序 EXE 文件名为 redirect.exe,您的命令行将是

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

您的 tasks.json 将如下所示:

And your tasks.json will look like the following:

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

这篇关于如何在 Visual Studio Code 任务中使用 stdin/stdout 重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆