Windows编写的Python代码在树莓派上调用NodeJS子进程失效解决方法
树莓派移植项目后subprocess调用Node脚本失败问题
原有代码
Windows端可正常运行的代码:
#Refresh the data by calling NodeJS API subprocess.call(['node', r'C:\Users\david\GrowattAPI\write.js'], shell=True)
树莓派上调整脚本路径后的代码:
#Refresh the data by calling NodeJS API subprocess.call(['node', '/home/pi/Documents/write.js'], shell=True)
异常情况
- 代码内调用Node脚本执行失败
- 树莓派终端手动执行
node /home/pi/Documents/write.js可正常运行 - 核心疑问:为何调整路径后代码调用失效?
最终解决方案
树莓派环境下该场景subprocess.call的正确写法为:
subprocess.call(['node /home/pi/Documents/write.js'], shell=True)
内容的提问来源于stack exchange,提问作者PradoEagle
相关产品推荐
相关产品推荐

