Visual Studio Code(vscode)で標準入力(STDIN)を与えつつプログラムをデバッグ実行したい場合。
"<" でファイルの内容をリダイレクトすれば良い。
Redirect input/output to/from the debug target
{
"name": "launch program that reads a file from stdin",
"type": "node",
"request": "launch",
"program": "program.js",
"console": "integratedTerminal",
"args": ["<", "in.txt"]
}
"args" に配列で与えるのがポイント。文字列で "< in.txt" のようにしてしまうと、エスケープされてしまってうまく動かない。
実行時に STDIN から任意のデータを入力するのは流石に無理。Python デバッガーは ${command:pickArgs} が使えるので、実行時に STDIN に渡すファイルを指定することはできる。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with STDIN",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"<",
"${command:pickArgs}"
]
}
]
}