I cannot found /dev/tty in Windows and handle it in python code. It could be CON or CON:
Here's my python script which accepts any combination of inputs from pipeline and from command line arguments as well as user's input from console:
#! python3
# -*- coding: utf-8 -*-
import sys
argv_tuple = [] # command line arguments
for arg in sys.argv:
argv_tuple.append( arg )
pipe_tuple = [] # values from pipeline
if not sys.stdin.isatty():
for line in sys.stdin:
pipe_tuple.append( line.replace('\n', '').replace('\r','') )
sys.stdin = open('CON:', mode='r', encoding=sys.stdin.encoding)
inpt_tuple = [] # inputs from the console
invalue = input(' … your input (`Enter` to quit) … ')
while not invalue == '':
inpt_tuple.append( invalue)
invalue = input(' … … ')
# # publish the results
print( len( argv_tuple), 'arguments:', argv_tuple)
print( len( pipe_tuple), 'pipelines:', pipe_tuple)
print( len( inpt_tuple), 'kbd input:', inpt_tuple)
Output:
dir /b py*.py | python_stdin.py a "b & c"
… your input (`Enter` to quit) … foo
… … bar
… …
3 arguments: ['D:\\bat\\python_stdin.py', 'a', 'b & c']
2 pipelines: ['pythonprint.py', 'python_stdin.py']
2 kbd input: ['foo', 'bar']
some cmd./dev/ttyas stdin direct.