Reputation: 119
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.
Upvotes: 4
Views: 10947
Reputation: 196
Based on Blake Daugherty's answer, I found the first pair of double quotes seems unnecessary:
code "D:\proj\directory-1" | exit
code "D:\proj\directory-2" | exit
exit
Upvotes: 2
Reputation: 11
One line code:
code C:\Users\MyUserName\path\to\my\project\directory pause
Upvotes: 0
Reputation: 93
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\Program Work\%folder%"
start mspaint.exe Work.png
code "" "C:\Users\TBD\Documents\Program Work\%folder%" | exit
Rem not needed but to be safe
exit
The C:\xPaintFileTemplate
is a folder in my C drive that contains only a png file named Work.png
. The png file is blank, and sized to what I want mspaint to open with. If there are more files in that folder, it will copy all of them, so be careful with xcopy!
The Rem
is a comment, saying the exit
command doesn't seem to be required but I added it in anyways as I believe it is good practice.
Upvotes: 8
Reputation: 31
Try using: 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
Upvotes: 1
Reputation: 119
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 .
Upvotes: 5
Reputation: 328
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"
Upvotes: 1