replit / ReplitClient.js

A JavaScript client library used to connect to the server-side code execution service
69 stars 13 forks source link

Handling stdin #2

Closed brianpmarks closed 9 years ago

brianpmarks commented 9 years ago

I'm trying out the python3 api over at trinket.io and can't find a good way to handle stdin from users. Is there a stdin option, similar to stdout, that could be passed to evaluate? Any other way to identify when a program is waiting for user input?

A trivial example in python might be:

a = input("Enter a thing: ")
print("This is your thing:", a)
b = input("Enter another thing: ")
print("This is your other thing:", b)
amasad commented 9 years ago

You can use the .write method to send a string to the process' stdin. Unfortunately, I found it really hard and unreliable to try to detect when a process is waiting for input across all languages I support.

One workaround could be that you monkey patch the input function in Python so you can insert your custom logic there.

brianpmarks commented 9 years ago

Thanks. I've got a rough implementation working now. Probably good enough for most situations.

Curious, did you monkey patch python input on the repl.it site? https://repl.it/BISI/2