for example, I want to to send `print(32) to python and it should print 32 and remain open until I press ctrl+d
I did following
echo 'print(32)' | python
but It just prints 32 and closes the python.
I want to keep the Python's interactive shell open to send further commands from my keyboard.
EDIT:
that was just example. instead of python it could be node, ruby or docker exec -it command.
basically I want to pipe output as if I was typing via my keyboard
Use the -i flag to ask python to inspect interactively after running a script, combine with process substitution <(..) construct in bash. This will let the python command assume the commands are coming from a file even though it isn't
python -i <(echo 'print(32)')
32
>>>
or set the PYTHONINSPECT variable to a non-empty string to emulate the -i behavior
PYTHONINSPECT=x python <(echo 'print(32)')
Note that Process substitution is not supported in POSIX mode, but on bash/zsh or ksh93 only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With