【PowerShell】vscodeのターミナル上でpythonの標準入力を表示させる

やりたいこと

test.txtに書いた内容をPythonの標準入力でvscodeのターミナル欄(powershell)に表示させたい

なおwindows10環境で動かす前提です。

実行するpythonスクリプト(tmp.py)

from sys import stdin
i = stdin.readline()
print(i)

表示したいテキストファイル(test.txt)

hoge

方法

通常のコマンドラインなら以下のようにできるが、PowerShellではできない

python tmp.py < test.txt

なのでPowerShellで以下のコマンドを入力

cat .\test.txt | python .\tmp.py

結果

成功した

コメント

タイトルとURLをコピーしました