Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind stdin? #12

Open
duzenko opened this issue Aug 22, 2023 · 6 comments
Open

Bind stdin? #12

duzenko opened this issue Aug 22, 2023 · 6 comments

Comments

@duzenko
Copy link

duzenko commented Aug 22, 2023

How do I bind a file to standard input stream?

E.g. same as if I run from command line

myprogram.exe < stdin.txt

So that all reads from stdin actually read from that file rather than keyboard input.

@kensheldon
Copy link

kensheldon commented Sep 12, 2023

@duzenko , would an exec-wrapper script suffice?
Your wrapper can modify the shell any way you like, as long as the last line is exec "$@"

Create the wrapper script:

#!/usr/bin/env bash
#
# a wrapper script to redirect stdin before running a command
#
exec 0< somefile.txt
exec "$@"

Then, add a startup command to your configuration

        {
            "type": "by-gdb",
            "request": "launch",
            "name": "blah blah blah",
            "program": "${workspaceRoot}/fee/fie/foe/fum",
            "cwd": "${workspaceRoot}/build/tests/fubar/",
            "programArgs": "yada yada yada",
            "preLaunchTask": "build target",
            "commandsBeforeExec": [
                "set exec-wrapper ${workspaceRoot}/utilities/wrapper.bash"
            ],
        }

@duzenko
Copy link
Author

duzenko commented Sep 12, 2023

@kensheldon maybe I'm doing something wrong but for me it does not read from the stdin this way
See the attached
image

pasvsc.zip

@kensheldon
Copy link

If you're running on windows, you may need a different shell for your wrapper script. You could try CMD or PowerShell. I would expect git-bash would suffice, but maybe not.

The exec-wrapper functionality is a feature of GDB. You can test this directly in GDB, without VSCode. Build your program as usual, but then open your favorite shell (bash shell, cmd shell, powershell, etc), and use GDB to run the program. Once it works in GDB, you can figure out the proper launch configuration for vscode and beyond-gdb.

@duzenko
Copy link
Author

duzenko commented Sep 13, 2023

I'd think an average user of vscode doesn't really use gdb directly and does not have experience with it - at least this is the case with me. If you don't have other suggestions then of course me neither.

@xuming
Copy link
Contributor

xuming commented Sep 14, 2023

You can write a pause in your program and run it .
After that, you can use "attach" to debug it .

@duzenko
Copy link
Author

duzenko commented Sep 15, 2023

Sounds like a feature gap in your plugin really

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants