问题
I want communication between racket program and python program.
My Racket code:
#lang racket
(define-values (sp o i e) (subprocess #f #f #f "hello.exe" ))
(display "server" i)
(flush-output i)
(display (read o))
My python code:
input_var = raw_input("Enter something: ")
print ("you entered " + input_var)
If i am just printing in my python program it works fine. If i am reading input from racket program it hangs. I want to read messages from racket.
回答1:
It looks like it's hanging because you failed to issue a newline (\n) to the output port. Here's how I ran your code:
#lang racket
(define-values (sp i o e) (subprocess #f #f #f
"/usr/bin/python"
"/tmp/foo.py"))
(display "server\n" o)
(flush-output o)
(display (read-line i))
... with the code you supplied in "/tmp/foo.py", and I saw the output:
Enter something: you entered server
... which is what I expected.
The only interesting difference here is that I appended a newline character to the output.
Note also that I swapped the names of your "o" and "i", because I didn't like the fact that "o" was an input port.
来源:https://stackoverflow.com/questions/9989009/communcation-between-racket-program-and-python-program