-1

I'm using windows 10 ming g++ compiler. When I was using macOS for compile and run at the same time I use the command.

g++ name.cpp && ./a.out

It worked but when I tried to use this in windows

g++ name.cpp && ./exe

it didn't work it shows an error message (The token '&&' is not a valid statement separator in this version).

So i use g++ name.cpp

./a.exe

but i want to run in a single line command.

  • 1
    you tried on powershell? –  Sep 05 '20 at 11:28
  • 4
    Try `g++ name.cpp & a.exe`. – HolyBlackCat Sep 05 '20 at 11:42
  • Or take a look at [tasks](https://code.visualstudio.com/docs/editor/tasks). You can specify that a specific task is executed before every launch. – Lukas-T Sep 05 '20 at 11:54
  • On Linux bash, a ';' separates multiple commands on a single command line, – 2785528 Sep 05 '20 at 12:10
  • why do you ask the same question again? [Compile and run at the same time with a single line command in windows (duplicate)](https://stackoverflow.com/q/63726754/995714) – phuclv Sep 05 '20 at 14:54
  • Does this answer your question? [Compile and run at the same time with a single line command in windows](https://stackoverflow.com/questions/63726754/compile-and-run-at-the-same-time-with-a-single-line-command-in-windows) – phuclv Sep 05 '20 at 14:54

1 Answers1

-1

This is actually a feature of the shell you're using to run the command(s). On MacOS it was most likely bash or zsh, while on Windows the default choice is probably cmd or PowerShell. The latter does not support && in a way similar to bash. Try changing the shell (terminal) in VS code settings using e.g. the doc page

Leo K
  • 182
  • 4
  • 1
    It worked but not int the way all i had to do was change terminal from powershell to cmd and then use the same command but with forward slash eg .> g++ name.cpp && .\a.exe – Sanskar Jaiswal Sep 05 '20 at 12:08
  • Alright, thanks for commenting! I'm not really that familiar with either cmd or PowerShell, should've stated it in the reply from the very beginning. I'll correct my answer to avoid misleading further readers about the power of cmd :) – Leo K Sep 05 '20 at 12:25