python传字符串方法
nodejs代码
// 获取传递的参数 (补环境可能会把process方法给删掉,这两行代码放在nodejs最上面进行赋值)
const __args = process.argv.slice(2);
// 执行逻辑
const result = __args[0] + __args[1];
// 将结果输出到标准输出
console.log('这是一条JB用没有的输出hello!!')
console.log(result);
python代码
import subprocess
# 启动Node.js进程并传递参数
node_process = subprocess.Popen(['node', '00_demo1.js', 'hello', 'python'], stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
# # 从Node.js进程中读取输出
# output = node_process.stdout.read().decode()
# print(f"Node.js output: {output}")
# 逐行读取输出,保留最后一行
last_line = ''
for line in node_process.stdout:
print('>>>>', line.decode())
last_line = line.decode().rstrip()
print(f"Node.js output: {last_line}")
python传字典方法
nodejs代码

最低0.47元/天 解锁文章
424

被折叠的 条评论
为什么被折叠?



