0

I am using VS Code to play with Rust. So far I have been unable to configure redirection of stdin from a file ("<", "in.txt" in args of launch.json).

I tried this launch.json

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "lldb",
            "request": "launch",
            "name": "Launch",
            "program": "${workspaceFolder}/target/debug/first.exe",
            "args":["<", "in.txt"],
            "cwd": "${workspaceFolder}",
            "console":"integratedTerminal"
        }
    ]
}

I tried also

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'first'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=first",
                    "--package=first"
                ],
                "filter": {
                    "name": "first",
                    "kind": "bin"
                }
            },
            "args": ["<", "in.txt"],
            "cwd": "${workspaceFolder}",
            "console" : "integratedTerminal"
        }
    ]
}

But nothing works.

E_net4
  • 27,810
  • 13
  • 101
  • 139
joel76
  • 5,565
  • 1
  • 18
  • 22
  • what you are trying to achieve? – Ashish Singh Aug 31 '22 at 09:40
  • I want to read a file as if it was user input via stdin. But it doesn't work beacause "<" seems to be reserved by "cargo". – joel76 Aug 31 '22 at 11:54
  • I have a very strong suspicion that this is an [XY problem](https://xyproblem.info/). Please provide your `launch.json` script. – Finomnis Aug 31 '22 at 12:06
  • *"I thought that rustc was an alternative for cargo"* - `rustc` is the compiler and `cargo` manages the entire ecosystem, like dependencies and features. `cargo` actually uses `rustc` to compile. – Finomnis Sep 01 '22 at 08:22
  • 1
    I don't see why this question has been downvoted. It is a valid question, and it shows some research effort, since may other places on the internet suggest adding `"<", "filename"` in the args in VSCode, including this accepted answer on SO https://stackoverflow.com/a/69744570/3811791, MS github and various blog posts. – Alexander Revo Dec 26 '22 at 11:34

1 Answers1

2

There is nothing wrong with cargo. Your problem is a very common problem and very easy to solve.

The real issue you are having is that CodeLLDB does not support args: ["<", "input.txt"]. Instead, it has the stdio config value to achieve the same thing.

{
    // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
    // Pointez pour afficher la description des attributs existants.
    // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Launch",
            "program": "${workspaceFolder}/target/debug/first.exe",
            "args": [],
            "stdio": "in.txt",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal"
        }
    ]
}
Finomnis
  • 18,094
  • 1
  • 20
  • 27