javascript - 从nodejs在anaconda环境中调用带有args的python文件
问题描述
我正在使用以下参数调用特定文件 main.py:
main.py --train --num_epoch 100 --id 93
在“gangan”的conda环境中
以下是我的代码:
const express = require('express')
const {spawn} = require('child_process');
const app = express()
const port = 3000
app.get('/', (req, res) => {
var dataToSend;
// spawn new child process to call the python script
const environmentName = 'gangan';
const pythonScript = './synthetic-time-series-smart-grid-master/main.py';
const command = `conda run -n ${environmentName} python ${pythonScript}`;
const python = spawn(command, { shell: true });
// collect data from script
python.stdout.on('data', function (data) {
console.log('Pipe data from python script ...');
dataToSend = data.toString();
});
// in close event we are sure that stream from child process is closed
python.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
// send data to browser
res.send(dataToSend)
});
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
我运行时得到的唯一输出是 在 HTMl中输入图像描述。
这是程序通常执行的方式 在此处输入图像描述
解决方案
推荐阅读
- spring-boot - Thymeleaf input type="date" 无法显示更新
- angular - Angular Material 6:无法读取 MatHeaderRowDef 表中未定义的属性“查找”
- r - 每年按月计算因子水平
- python - 在 Python 中安装包 mapclassify 时出错
- react-native - 在 react-native 中导航时检测键盘模式
- c# - RSA加密:参数不正确
- wordpress - Wordpress 从用户那里获取帖子[关系]
- java - 在本地计算机上使用 DynamoDB 进行非常慢的保存操作
- docker - 在 Docker 中运行 Keycloak 时出错
- windows - 使用 PowerShell 的 SOAP Web 服务的正确参数数量