Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对命令行(node.js)中的数据使用自定义(“动态”)javascript函数_Javascript_Node.js_Command Line_Command Line Interface - Fatal编程技术网

对命令行(node.js)中的数据使用自定义(“动态”)javascript函数

对命令行(node.js)中的数据使用自定义(“动态”)javascript函数,javascript,node.js,command-line,command-line-interface,Javascript,Node.js,Command Line,Command Line Interface,有没有一种方法可以使用javascript函数“通过管道传输数据” 差不多 $ curl -s https://api.github.com/users/egamma/gists | node.exe --magic "JSON.parse(arguments[0]).map(x=>x.files[0].filename + ' -- ' + x.description)" | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/" test.js .esl

有没有一种方法可以使用javascript函数“通过管道传输数据”

差不多

$ curl -s https://api.github.com/users/egamma/gists
  | node.exe --magic "JSON.parse(arguments[0]).map(x=>x.files[0].filename + ' -- ' + x.description)"
  | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json  Visual Studio Code default .eslintrc.json
甚至

$ curl -s https://api.github.com/users/egamma/gists
  | node.exe --magic "x=>JSON.parse(x).map(y=>y.files[0].filename + ' -- ' + y.description)"
  | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json  Visual Studio Code default .eslintrc.json

Node.js有
-e
-p
,它们只能作为参数使用,所以我不知道如何将数据(参数)和代码分开。此外,使用参数会限制数据长度

不写临时文件的难看的解决方法是

$ node.exe -p "JSON.parse($(curl -s https://api.github.com/users/egamma/gists)).map(x=>x.files[0].filename + ' -- ' + x.description)"
  | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json  Visual Studio Code default .eslintrc.json

(注意,我在Windows上使用Git Bash,因此,
node.exe
是一种解决方法)

或者您可以放弃尝试使用node,直接使用。或者您可以放弃尝试使用node,直接使用。
$ node.exe -p "JSON.parse($(curl -s https://api.github.com/users/egamma/gists)).map(x=>x.files[0].filename + ' -- ' + x.description)"
  | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json  Visual Studio Code default .eslintrc.json