在nodejs中运行bat文件时获得空白cmd提示

编程入门 行业动态 更新时间:2024-10-24 17:20:23

在nodejs中运行bat文件时获得<a href=https://www.elefans.com/category/jswz/34/1766909.html style=空白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提示

本文发布于:2024-05-07 07:12:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空白   提示   文件   nodejs   bat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!