対話型である可能性がある、または直接データをパイプ処理する可能性がある、PowerShellから呼び出すサブプロセスがあります。例えば:
# This is interactive:
& c:\python27\python.exe
# This takes redirected input:
echo hi | & c:\python27\python.exe -c "print repr(raw_input())"
そのようなプロセスへの呼び出しをラップするために使用できる関数を作成したいです。私がすることができます:
function python() {
& c:\python27\python.exe @args
}
# This starts an interactive prompt:
python
# The piped data disappears and the process still reads from the console:
echo hi | python -c "print repr(raw_input())"
または私はこれを行うことができます:
function python() {
$input | & c:\python27\python.exe @args
}
# This doesn't accept interactive input:
python
# The piped data is passed through to the sub-process as intended:
echo hi | python -c "print repr(raw_input())"
両方のケースを処理する関数を書く方法を私は理解することができません。パイプラインなしで呼び出された場合は標準入力から読み込むサブプロセスを起動し、パイプライン入力で呼び出された場合はサブプロセスの標準入力に渡します。これはできますか?