Vscode-docs: debug: explain how to redirect input/output from/to the debug target

Created on 21 Feb 2017  路  9Comments  路  Source: microsoft/vscode-docs

Most helpful comment

@gregvanl here is what we could say:

"Redirect input/output from/to the debug target"

Redirecting input/output is debugger/runtime specific, so VS Code does not have a built-in solution that works for all debuggers.

Here are two approaches you might want to consider:

  1. launch the program to debug (aka debug target) manually in a terminal shell and redirect input/output as needed. Pass command line options to the debug target to enable that a debugger can attach to it. Create and run an "attach" debug configuration that attaches to the debug target.
  2. if the debugger extension you are using allows to run the debug target in VS Code's integrated terminal (or an external terminal), you can try to pass the shell redirect syntax (e.g. "<" or ">") as arguments. E.g.:
    { "name": "launch program that reads a file from stdin", "type": "node", "request": "launch", "program": "program.js", "console": "integratedTerminal", "args": [ "<", "in.txt" ] }
    This approach requires that the "<" syntax survives the debugger extension and ends up unmodified in the integrated terminal.

All 9 comments

Hi, everyone!
How can I redirect this output data (while debugging) to my extension?

@mike-prokaziuk I don't understand what you mean.

I develop an extension for VS Code.
I launch child process by using 'spawn' command and attach to him. In this case I can subscribe to 'cp' events and receive data.
But, I wanted to try launch this process using VS Code capabilities and 'launch.json' file.
The process has started and the VS Code has attached to them, but I don't understand how to receive the data from him :) .
The 'process' is simple console app.

{
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "<",
                "in.txt"
              ]
        }

No effect. File is not redirecting.

I updated python to 3.7.2 and it started working!

This simple "docs addition" is open for 2 years...
And currently I'm unable to make this work.
This is my launch configuration:

    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/myapp.dll",
        "args": ["<", "/Users/guyarad/src/input.txt"],
        "cwd": "${workspaceFolder}",
        "console": "integratedTerminal",
        "stopAtEntry": false
    }

Any ideas?

Example use case

The Pino logger recommends piping the output to a "prettifier" when developing, it avoids the use of including dev libraries in code.

@gregvanl here is what we could say:

"Redirect input/output from/to the debug target"

Redirecting input/output is debugger/runtime specific, so VS Code does not have a built-in solution that works for all debuggers.

Here are two approaches you might want to consider:

  1. launch the program to debug (aka debug target) manually in a terminal shell and redirect input/output as needed. Pass command line options to the debug target to enable that a debugger can attach to it. Create and run an "attach" debug configuration that attaches to the debug target.
  2. if the debugger extension you are using allows to run the debug target in VS Code's integrated terminal (or an external terminal), you can try to pass the shell redirect syntax (e.g. "<" or ">") as arguments. E.g.:
    { "name": "launch program that reads a file from stdin", "type": "node", "request": "launch", "program": "program.js", "console": "integratedTerminal", "args": [ "<", "in.txt" ] }
    This approach requires that the "<" syntax survives the debugger extension and ends up unmodified in the integrated terminal.

Any clue on how to do the same thing in powershell ? I need to add Get-Content <file> | .. before my command

Was this page helpful?
0 / 5 - 0 ratings