[英]Can node js pass command line arguments to twojs in the same line?
I am new to Node.js.我是 Node.js 的新手。 Recently, I am building a script as below:
最近,我正在构建一个脚本,如下所示:
"updateData": "node runFirstScript.js && node runSecondScript.js",
"build:desktop": "npm run updateData env1",
"build:mobile": "npm run updateData env2",
I am expecting runFirstScript.js and runSecondScript.js can get the parameters env1
and env2
while they are executed.我期待runFirstScript.js和runSecondScript.js在执行时可以获得参数
env1
和env2
。
Instead of separating as below:而不是分开如下:
"updateData1": "node runFirstScript.js",
"updateData2": "node runFirstScript.js",
"build:desktop": "npm run updateData1 env1 && npm run updateData2 env1",
"build:mobile": "npm run updateData1 env2 && npm run updateData2 env2",
Is there any optimum solution for this?有什么最佳解决方案吗? Thanks
谢谢
Just change && to & ,here is the reason what each symbol mean:只需将 && 更改为 & ,这就是每个符号的含义的原因:
& is to make the command run in background. &是让命令在后台运行。 You can execute more than one command in the background, in a single go.
您可以在后台执行多个命令,在单个 go 中。 For eg:
Command1 & Command2 & Command3
例如:
Command1 & Command2 & Command3
&& is to make following commands run only if preceding command succeeds.For eg: Lets say we have Command1 && Command2 && Command3
. &&是仅在前面的命令成功时才运行以下命令。例如:假设我们有
Command1 && Command2 && Command3
。 Command2 will only execute if Command1 succeed.只有当 Command1 成功时,Command2 才会执行。
Bonus: ;奖金: ; which is useful in your daily productivity , You can run several commands in a single go and the execution of command occurs sequentially.
这对您的日常生产力很有用,您可以在单个 go 中运行多个命令,并且命令的执行顺序发生。 For eg:
Command1; Command2; Command3
例如:
Command1; Command2; Command3
Command1; Command2; Command3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.