【发布时间】:2015-08-24 00:51:14
【问题描述】:
概述
我想将参数传递给来自标准输入的节点脚本。
一般来说,我正在拍摄这样的东西
nodeScript.js | node {{--attach-args??}} --verbose --dry-run
作用与
相同node nodeScript.js --verbose --dry-run
更多细节
这是一个简化的脚本用于说明,dumpargs.js
console.log("the arguments you passed in were");
console.log(process.argv);
console.log("");
这样你就可以:
node dumpargs.js --verbose --dry-run file.txt
[ 'node',
'/home/bill-murray/Documents/dumpargs.js',
'--verbose',
'--dry-run',
'file.js' ]
现在的问题是,如果该脚本通过标准输入进入(例如,通过 cat 或 curl)
cat dumpars.js | node
the arguments you passed in were
[ 'node' ]
有没有好办法给它传递参数?
不是节点:使用 bash,这次使用
dumpargs.shecho "the arguments you passed in were" printf "> $@" echo答案看起来像
cat dumpargs.sh | bash -s - "--verbose --dry-run file.txt" the arguments you passed in were > --verbose --dry-run file.txt
【问题讨论】: