Thx! sys.stdout.flush() works but in real use cases I cannot add 
sys.stdout.flush() to every python print.
Can I do anything in the racket side to solve the problem? Making the 
interactive window behave like terminal perhaps?

On Wednesday, May 20, 2020 at 4:49:30 PM UTC+8, Alex Harsanyi wrote:
>
> Short version: Try adding a "sys.stdout.flush()" after each of your print 
> statements in your python script.
>
> Longer version: when you run that program in a terminal, the output is a 
> TTY and the standard output is flushed after every line.  When you run it 
> as a subprocess, the standard output is a pipe and it is buffered.
>
> This is not Racket specific, you would get the same problem if you ran 
> "os.system("test.py")" in another python program.
>
> Alex.
>
> On Wednesday, May 20, 2020 at 4:15:02 PM UTC+8, Rock Nie wrote:
>>
>> This only happens in DrRacket.
>>
>> On Wednesday, May 20, 2020 at 1:16:44 PM UTC+8, Rock Nie wrote:
>>>
>>> I am running the system procedure in drracket's interactive window
>>> (system "test.py")
>>>
>>> where test.py is
>>> #!/home/utils/Python-3.8.0/bin/python3
>>> import os
>>>
>>> print("Running cmd: date1")
>>> print("Running cmd: date2")
>>> os.system("date")
>>> print("Running cmd: date3")
>>> os.system("date")
>>>
>>> and the output is
>>> Tue May 19 22:14:19 PDT 2020
>>> Tue May 19 22:14:19 PDT 2020
>>> Running cmd: date1
>>> Running cmd: date2
>>> Running cmd: date3
>>> #t
>>>
>>> which is different from my expectation, can anyone help explain why?
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/3cc7befb-8cf9-4339-a9d9-452204ae67f6%40googlegroups.com.

Reply via email to