[英]Run .vbs script with node
I am trying to find out how I can run a .vbs
file from a node application. 我试图找出如何从节点应用程序运行
.vbs
文件。
The script does it's own thing and my node application doesn't need any info back except maybe when the script is finished running. 脚本是自己做的,我的节点应用程序不需要任何信息,除非脚本运行完毕。
When I find a way to do this I will then look at passing parameters to the script, but for now I just need to know how I can run the script. 当我找到一种方法来执行此操作时,我将查看将参数传递给脚本,但是现在我只需要知道如何运行脚本。
Thanks 谢谢
Use child_process.spawnSync(command[, args][, options])
. 使用
child_process.spawnSync(command[, args][, options])
。 See a , b . 见a , b 。 Demo:
演示:
Given: 鉴于:
|..
+---vbs
| slave.vbs
|
\---nodejs
master.js
slave.vbs: slave.vbs:
Option Explicit
Dim a : a = "no arg"
If 0 < WScript.Arguments.Count Then a = WScript.Arguments(0)
Dim o : o = Array("", WScript.ScriptName, a, Time())
o(0) = "MsgBox"
MsgBox Join(o, "|")
o(0) = "StdOut"
WScript.Stdout.WriteLine Join(o, "|")
o(0) = "StdErr"
WScript.Stderr.WriteLine Join(o, "|")
WScript.Quit 3
master.js: master.js:
'use strict';
const
spawn = require( 'child_process' ).spawnSync,
vbs = spawn( 'cscript.exe', [ '../vbs/slave.vbs', 'one' ] );
console.log( `stderr: ${vbs.stderr.toString()}` );
console.log( `stdout: ${vbs.stdout.toString()}` );
console.log( `status: ${vbs.status}` );
output: 输出:
node master.js
(MessageBox)
stderr: StdErr|slave.vbs|one|14:09:39
stdout: StdOut|slave.vbs|one|14:09:39
status: 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.