2023-08-23 21:56:25 +02:00
|
|
|
import platform
|
|
|
|
|
2023-06-15 16:39:08 +02:00
|
|
|
import structio
|
|
|
|
import subprocess
|
|
|
|
import shlex
|
|
|
|
|
|
|
|
|
|
|
|
async def main(data: str):
|
2023-08-23 21:56:25 +02:00
|
|
|
cmd = shlex.split("python -c 'print(input())'")
|
|
|
|
to_send = data.encode(errors="ignore")
|
2023-06-15 16:39:08 +02:00
|
|
|
# This will print data to stdout
|
2023-08-23 21:56:25 +02:00
|
|
|
await structio.parallel.run(cmd, input=to_send)
|
2023-06-15 16:39:08 +02:00
|
|
|
# Other option
|
2023-08-23 21:56:25 +02:00
|
|
|
out = await structio.parallel.check_output(cmd, input=to_send)
|
|
|
|
# Thanks to Linux, Mac OS X and Windows all using different
|
|
|
|
# line endings, we have to do this abomination
|
|
|
|
out = out.decode().rstrip("\r").rstrip("\r\n").rstrip("\n")
|
|
|
|
assert out == data
|
2023-06-15 16:39:08 +02:00
|
|
|
# Other, other option :D
|
2023-06-19 17:34:44 +02:00
|
|
|
process = structio.parallel.Popen(
|
|
|
|
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
|
|
|
)
|
2023-08-23 21:56:25 +02:00
|
|
|
out, _ = await process.communicate(to_send)
|
|
|
|
out = out.decode().rstrip("\r").rstrip("\r\n").rstrip("\n")
|
|
|
|
assert out == data
|
2023-06-15 16:39:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
structio.run(main, "owo")
|