【发布时间】:2021-03-05 03:50:26
【问题描述】:
我正在尝试使用 spawn child_process 运行 python 脚本。在运行 nodemon app.js 时,我已经设法让它工作,但是我想打包我的节点应用程序并让它运行一个 python 脚本。一旦我使用以下方式打包应用程序:
pkg .
它似乎能够运行代码,因为没有返回错误,但是 python 脚本似乎不起作用。 Python 脚本会创建一些测试数据并将其保存到 .csv 文件中,然后节点将使用 Tail 查看该文件。
Python 脚本:
import random
import time
import datetime
import math
import sys
cwd = ""
if len(sys.argv) == 2:
cwd = sys.argv[1]
print(cwd)
x = 0
y = 0
z = 0
while(True):
x = x + 0.1
y += 1
f = open( cwd + "./public/data.csv", "a")
csv_writer = writer(f)
num1 = random.randrange(50,120)
num2 = random.randrange(50,120)
num3 = math.sin(x)
num4 = str(datetime.datetime.now().time()).split('.')[0] + "." + str(datetime.datetime.now().time()).split('.')[1][0:3]
print(num4)
csv_writer.writerow([num1,num2,num3,num4])
f.close()
app.js中设置的节点尾:
tail = new Tail("./public/data.csv");
这是我生成子进程的代码:
router.post("/testing/start", function (req, res) {
/**
* Start the python script. The python script will start generating the data.
* @memberof TestingRoutes.PythonScripts
* @function
* @name post
* @param '/testing/start' The url
* @instance
*/
python = spawn('python', ['./test.py', process.cwd()]);
testing_status = true;
res.send("success");
})
我的想法是,这与脚本所在的位置与可执行文件所在的位置有关。或者它与尾巴的方向有关。但是,我查看了活动监视器以查看在我启动脚本后是否有 Python 进程正在运行,并且似乎没有任何 Python 程序正在运行。是否可以在节点可执行文件中从节点启动 python 脚本?
任何帮助将不胜感激!
【问题讨论】:
-
我在哪一行得到错误?
-
classList不是 jQuery 对象的属性。阅读文档:api.jquery.com/removeClass & api.jquery.com/addClass。还有exec(),但我不知道你期望它在你使用它的上下文中做什么。
标签: javascript python html jquery node.js