簡體   English   中英

在 nodejs 中運行 bat 文件時出現空白 cmd 提示

[英]Getting a blank cmd prompt on running a bat file in nodejs

我正在嘗試通過在 nodejs 中將 arguments 傳遞給它來運行 .bat 文件。 但是,我得到一個空的命令提示符。 如何獲取粘貼在路徑上的命令。

代碼 -

服務器.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%"

output img 文件是 -

命令提示符

NodeJS 在本節中徹底記錄了在 Windows 上生成批處理文件的問題。

摘抄:

When running on Windows, .bat and.cmd files can be invoked using child_process.spawn() with the shell option set, with child_process.exec(), or by spawning cmd.exe and passing the.bat or.cmd file as an參數(這是 shell 選項和 child_process.exec() 所做的)。

 const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM