0

I have had a setup for a while to run C++ programs in VS Code. It was basically a tasks.json which looked like this

"tasks": [
      {
        "label": "Compile and run",
        "type": "shell",
        "command": "",
        "args": [
          "g++",
          "${fileBasename}",
          "-o",
          "test",
          "&&",
           ...
   }

I had also kept a settings.json to define the terminal to be used which was command Prompt, For some reason in the latest update for VS Code my setup got messed and it does not work anymore.

I would like to know the right syntax to define cmd as the terminal for running the tasks since things like && < > dont work in powershell

rupeshraj
  • 1
  • 2
  • I do know nothing about `tasks` in Visual Code, but `&&` seems to work, see: [How do I run multiple commands on one line in PowerShell?](https://superuser.com/questions/612409/how-do-i-run-multiple-commands-on-one-line-in-powershell) and `< and >` also work in powershell. – Luuk May 30 '21 at 09:13
  • when I say `< and >` I mean they dont work for input output redirection, `g++ ECODOWN.cpp -o test ; test < input.txt > output.txt;` here is a cmd for refernce – rupeshraj May 30 '21 at 12:28
  • this might help: https://stackoverflow.com/questions/44243949/how-to-use-stdin-stdout-redirect-in-visual-studio-code-task – Luuk May 30 '21 at 12:45
  • @Luuk Yes this also worked – rupeshraj May 30 '21 at 12:47

1 Answers1

0

After Luuk's comment I did more digging and found the followig to work for my vs code tasks problem. I only had to change && to ; and for the input out redirection I used this answer. Now my tasks.json looks like this

 "tasks": [
      {
        "label": "Compile and run",
        "type": "shell",
        "command": "",
        "args": [
          "g++",
          "${fileBasename}",
          "-o",
          "test",
          ";",
          "cmd",
          "/c",
          "'test.exe < input.txt > output.txt'",
          ";",
          "del",
          "*exe",
          ";",
          "del",
          "${fileBasename}"
        }
]
rupeshraj
  • 1
  • 2