空白cmd提示"/>
在nodejs中运行bat文件时获得空白cmd提示
我正在尝试通过在nodejs中向其传递参数来运行.bat文件。但是,我得到一个空的命令提示符。如何将命令粘贴到路径上。
代码-
server.js
var bat = require.resolve('E:/API_Gateway_through_Swagger/New_Project/aws-bat-file-3.bat');
var num = "123"
var state_desc = "abc";
var ls = spawn(bat, [num, state_desc ]);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
蝙蝠文件-
aws-bat-file-3.bat
echo off
echo "Batch Started"
set arg1=%1
set arg2=%2
START "Task Options" cmd.exe /b " cd C:\Users\myfolder & aws apigateway create deployment --rest-api-id %arg1% --stage-name dev --stage-description %arg2%"
输出img文件为-
回答如下:NodeJS记录了在Windows in this section上彻底生成批处理文件的问题。
摘录:
[在Windows上运行时,可以使用设置了shell选项的child_process.spawn(),child_process.exec()或生成cmd.exe并传递.bat或.cmd文件来调用.bat和.cmd文件作为参数(这是shell选项和child_process.exec()的作用)。
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true });
更多推荐
在nodejs中运行bat文件时获得空白cmd提示
发布评论