简体   繁体   English

如何在单个npm运行脚本中将命令的结果传递给另一个命令的选项?

[英]How do I pass the result from a command to another command's option in a single npm run script?

I'm not sure whether this is possible in a single line, but I want to run yaml2json and pass the result json to jade -O option in CLI. 我不确定单行是否可行,但是我想运行yaml2json并将结果json传递给CLI中的jade -O选项。

I know if I write the json file and specify the output file path in -O option, it works. 我知道如果我写json文件并在-O选项中指定输出文件路径,它就可以工作。 But I would rather not write some temporary file if this can be done without it. 但是,如果没有它,我不愿写一些临时文件。

So This works 所以这有效

{
  "scripts": {
    "jade": "yaml2json src/data/site.yaml > temp.json && jade src/jade/pages --out dist -O temp.json",
  }
}

However this doesn't. 但是,事实并非如此。

{
  "scripts": {
    "jade": "jade src/jade/pages --out dist -O yaml2json src/data/site.yaml"
  }
}

Any help or insight would be appreciated. 任何帮助或见解将不胜感激。

Have you tried using backticks (the grave)? 您是否尝试过使用反引号(坟墓)?

{
  "scripts": {
    "jade": "jade src/jade/pages --out dist -O \"`yaml2json src/data/site.yaml`\""
  }
}

Or you could remove the temporary file afterwards if it is lingering (Linux/OSX only): 或者,如果暂时存在,您可以在以后删除该临时文件(仅适用于Linux / OSX):

{
  "scripts": {
    "jade": "yaml2json src/data/site.yaml > temp.json && jade src/jade/pages --out dist -O temp.json && rm temp.json",
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 arguments 从命令行传递到 python 脚本以读取和更新 json 文件中存在的某些键的值 - How do I pass arguments from command line to the python script to read and update values of certain keys present in a json file 如何将参数传递到sed命令中 - How do I pass parameters into a sed command 如何在Perl脚本中将变量传递给curl命令? - How to pass a variable to curl command in perl script? 为什么我不能在 mac 上成功运行“npm start”命令? - Why can't I successfully run “npm start” command on mac? 如何为此curl命令修复shell脚本 - How do I fix my shell script for this curl command 如何通过npm run-script将标志传递给nodejs应用程序? - How to pass flags to nodejs application through npm run-script? 当我以“npm install”的形式执行命令时,它出现 npm ERR code ENOENT npm ERR - When I do command as "npm install" it comes npm ERR code ENOENT npm ERR 如何使用Spring的RestTemplate等效于curl命令? - How I do the equivalent of this curl command using Spring's RestTemplate? 我们如何在单行 python 命令中传递参数 - How can we pass argument in single line python command jq - 使用单个命令从另一个数组中减去一个数组 - jq - subtracting one array from another using a single command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM