如何从命令行将脚本导入NodeJ?

时间:2022-06-08 14:03:48

From command line, I'd like to take a script from my paste board (FYI: pbpaste is an OSX feature) and pipe it into the Node's repl command line tool. For example:

从命令行,我想从我的粘贴板(FYI:pbpaste是一个OSX功能)中获取一个脚本并将其传递到Node的repl命令行工具中。例如:

pbpaste | node -e

pbpaste |节点-e

This does not evaluate the contents in my clipboard. How do I get the runtime to do this?

这不会评估剪贴板中的内容。如何让运行时执行此操作?

2 个解决方案

#1


8  

The -e option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to node directly.

-e选项用于运行作为参数传递的JS。要从stdin运行JS,您可以直接管道到节点。

pbpaste | node

#2


4  

This seems to do the trick:

这似乎可以解决问题:

node -e "$(pbpaste)"

node -e“$(pbpaste)”

#1


8  

The -e option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to node directly.

-e选项用于运行作为参数传递的JS。要从stdin运行JS,您可以直接管道到节点。

pbpaste | node

#2


4  

This seems to do the trick:

这似乎可以解决问题:

node -e "$(pbpaste)"

node -e“$(pbpaste)”