【发布时间】:2021-05-02 19:39:17
【问题描述】:
我是 Node.JS 和 JavaScript 的新手,但我正在尝试运行由 Node.JS API 启动的 PowerShell 进程,并将该子进程的输出作为 Express 响应返回。
这是我的 test.ps1:
write-host "Line1"
Write-Host "Line2"
Write-Host "Line3"
这是我的 Node.JS 代码:
// test
// http://localhost:4420/test
Router.get('/test', function(req, res) {
const { exec } = require('child_process');
exec(`.\\server\\scripts\\test.ps1`, {'shell':'powershell.exe'}, (error, stdout, stderr)=> {res.send(stdout)})
});
当前的输出是这样的:
Line1 Line2 Line3
我想要这样:
Line1
Line2
Line3
【问题讨论】:
标签: node.js powershell api rest express