python - Windows OS下Nodejs运行python脚本
问题描述
我有一个简单的 python 脚本(在 windows os 下完美运行),我想用 nodejs 执行。所以我建立了nodejs服务器,我建立了html页面,一切都在windows下运行。但是我的python脚本没有运行......相同的nodejs服务器+ html页面+脚本在raspbian OS下完美运行。所以我不明白错误在哪里。有人可以帮我找出错误吗?谢谢。
nodejs服务器:
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const formidable = require('formidable');
const path = require('path');
const PORT = 8000;
var fs = require('fs');
const {execFile, exec, spawn} = require ('child_process');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function (req, res){
res.sendFile(__dirname + '/public/index.html');
});
function runScript(){
return spawn('python', [
path.join(__dirname + '/public/script.py'),
]);
}
app.post('/start', function(req, res){
const subprocess = runScript()
res.sendFile(__dirname + '/public/index.html');
console.log('script launched')
});
app.listen(8000, function () {
console.log('Server Started on Port : 8000 !')
})
html页面(简历):
<div id="right">
<form action="/start" method="post">
<input title="Clic to Start " type="submit" id="state" value="START">
</form>
<form action="/replay" method="post">
<input title="Clic to stop" type="submit" id="state" value="STOP">
</form>
</div>
剧本 :
# coding: utf-8
import os, sys
import subprocess
import time
import json
global listedouble
listedouble=[]
def wol():
counter = 0
while counter < 100:
counter = counter + 1
print(counter)
if counter == 100:
print("le compteur est arrive a 1000")
def save():
File_name = "TEST_python"
with open("C:/Users/430154/Desktop/nodejs/public/"+File_name+".json", "w") as file: # ici le repertoire correspond au repertoire raspberry
json.dump(listedouble, file)
wol()
save()
非常感谢。
解决方案
推荐阅读
- tree - 单值二叉树
- linux - 尝试执行 elf 文件时出现非法指令(核心转储)
- graphql - 在突变输入类型上使用 GraphQL 模式指令
- ruby - 为什么符号不等于符号
- python - Concat 无法识别连接的列之间的共享索引
- reactjs - ReactStrap Modal设置状态下的Form
- javascript - 将 Javascript 插入管理员页脚 wordpress
- c# - 在 Inspector 中分配的 Unity 值在代码中抛出 Null
- sql - 显示至少在十个不同地方(地点)参加过比赛的运动员人数的 SQL 查询
- go - 如何在 GORM 中使用从 BOM 到 Part 的两个外键来实现特定的 Part/BOM 设计?