使用节点运行 .vbs 脚本 [英] Run .vbs script with node

查看:42
本文介绍了使用节点运行 .vbs 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何从节点应用程序运行 .vbs 文件.

I am trying to find out how I can run a .vbs file from a node application.

脚本做它自己的事情,我的节点应用程序不需要任何信息,除非脚本完成运行.

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.

谢谢

推荐答案

使用 child_process.spawnSync(command[, args][, options]).请参阅ab.演示:

Use child_process.spawnSync(command[, args][, options]). See a, b. Demo:

给定:

|..
+---vbs
|       slave.vbs
|
\---nodejs
        master.js

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:

'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}` );

输出:

node master.js

(MessageBox)

stderr: StdErr|slave.vbs|one|14:09:39

stdout: StdOut|slave.vbs|one|14:09:39

status: 3

这篇关于使用节点运行 .vbs 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆