4

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.

Marcin
  • 48,559
  • 18
  • 128
  • 201
chom
  • 265
  • 1
  • 5
  • 16
  • How are you trying to connect their stdin and stdout? How are you running these programmes? – Marcin Apr 03 '12 at 07:39

1 Answers1

6

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.

John Clements
  • 16,895
  • 3
  • 37
  • 52