노드 모듈 PythonShell을 사용하여 Python과 통신하는 nw.js 응용 프로그램을 만들려고합니다.노드의 PythonShell (nwjs)
내가 겪고있는 문제는 stdin을 닫지 않으면 콘솔에 아무 것도 기록되지 않는다는 것입니다. 그러나 스트림을 열어서 Python 스크립트에 여러 명령을 보내고 Python의 상태를 저장할 수 있도록하고 싶습니다. 여기
내 스크립트입니다 :script.py
import sys
def main():
command = sys.stdin.readlines() # unused for now
sys.stdout.write("HELLO WORLD")
sys.stdout.flush()
if __name__ == '__main__':
main()
main.js이 시점에서
var PythonShell = require('python-shell');
var pyshell = new PythonShell('script.py');
pyshell.on('message', function (message) {
console.log(message);
});
pyshell.send('hello');
아무 일도 발생하지 않습니다.
pyshell.end()
을 입력하면 HELLO WORLD
이 콘솔에 출력됩니다. 그런데 더 이상 pyshell.send
명령을 사용할 수 없습니다.
어떻게 파이썬 자식 프로세스가 실행 중이며 입력을 기다리고 있지만 모든 출력을 JS로 파이프 할 수 있습니까?
같은 문제가있는 pythonshell 대신에'child_process.spawn' 모듈을 직접 사용해 보았습니다. – Jeff