Disclaimer: I read this and this before, but it doesn't work as I want.
Description: I decided to create set of batch files for convenient way to run different projects in VSCode from desktop in one click(double-click). I want close cmd terminal after running a batch file, but terminal remains. I tried:
start code "C:\Users\MyUserName\path\to\my\project\directory"
and
cmd /c start code "C:\Users\MyUserName\path\to\my\project\directory"
It quickly runs command, runs code and opens my project, then, it seems to me, closes terminal and runs a new one in desktop directory.
I found solution with help of DavidPostill . This works fine for me:
start "" cmd /b /c code "C:\Users\MyUserName\path\to\my\project\directory" && exit 0
UPDATE: There is a more simple way to run VSCode using command line interface:
cd path/to/my/project
code .
Try using: start cmd /C code . :0
start cmd /C code . :0
It should be able to close the cmd terminal. At least that worked for me on my Windows 10.
Another version:
start cmd /C code "C:\\Users\\MyUserName\\path\\to\\my\\project\\directory" :0
None of the above worked for me; at worst one of the left-over CMD's needed its close button clicking three times before it would go away.
I tried the URL method and this worked just as I wanted: VSCode opened, and the cmd window went away; my batch file ( "VSCode on project.bat"
) contains just one line:
start vscode://file/C:/path/to/project
or:
start "" "vscode://file/C:/path/to/project"
If anyone else comes across this in 2022, I found a solution that works great for me.
code "" "C:\path\to\folder\with\project" | exit
Also, below is my batch I made for a quick workspace that:
Hope this helps someone like me who doesn't know everything about batch files!
@echo off &setlocal
set /p "folder=Enter the folder name to be created: "
md "%folder%" ||(pause &goto :eof)
cd %folder%
echo. > Things_I_had_to_look_up.txt
echo. > Answers.txt
dotnet new console
xcopy /s "C:\xPaintFileTemplate" "C:\Users\TBD\Documents\Interview Program Work\%folder%"
start mspaint.exe Work.png
code "" "C:\Users\TBD\Documents\Interview Program Work\%folder%" | exit
Rem not needed but to be safe
exit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.