'vscode code runner: excute codes in external terminal and pause it
My intention is
- to make code run in external terminal
- to pause that terminal so I can see the result.
Original code-runner setting which runs code in the integrated terminal was
"code-runner.executorMap":{
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
...
}
I've managed to make codes run in external terminal using this code:
"code-runner.executorMap":{
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && start $fileNameWithoutExt.exe",
...
}
But the terminal disappears so quickly that I can't see the result.
I've tried the fourth answer on the link above:
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && Start pwsh -Command \"& {.\\$fileNameWithoutExt.exe; pause}\"",
but it doesn't work for me as vscode says: A parameter cannot be found that matches parameter name 'Command'.
I also tried
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && start $fileNameWithoutExt.exe && pause",
but external terminal still disappears and "pause" makes integrated terminal to pause.
Then I tried
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && start cmd /k $fileNameWithoutExt.exe"
I thought "start cmd" opens new command prompt and "/k" would let it continue.
(https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd)
It still doesn't work and vscode says: A positional parameter cannot be found that accepts argument hw3.exe
. (hw3 is the name of my file)
I know there is code-runner:run
in terminal- whether to run code in integrated terminal setting in Files>Preferences>Settings>User
but there are several folders in my workspace and I intend to run code in external terminal for this specific folder only. So I keep that setting checked and working with settings.json which is unique to this folder.
Thanks for your time and stay safe!!
Solution 1:[1]
This should do the trick:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -O2 -std=c++17 $fileName -o $fileNameWithoutExt && start cmd \"/k ; $fileNameWithoutExt\""
},
Solution 2:[2]
The previous answer cannot let me just click once to exit the cmd.
(I think it's a little annoying.)
I think use "/c" with "&pause" is better.
(Actually, we just need one "&" and I don't know why :P)
The most comfortable version I think is as follows:
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && start cmd \"/c ; $fileNameWithoutExt &pause\"",
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Deep Raval |
Solution 2 | JoyYoutuLee |