If you listed out the commands in the previous recipe, scroll up to find what cmdlets might help you with this recipe.
- At the prompt, type in the following to start Visual Studio Code.
PS> Start-Process code
Ensure that the status bar at the bottom is not blue. If it is blue, read the Getting Ready section of this recipe. Press Ctrl + Shift + E or click on Explorer icon on the left sidebar of VS Code. There should not be any directory open there.
- Open VS Code at the directory you created the hello-world script.
PS> Start-Process code -ArgumentList /home/ram/Documents/code/github/powershell/
Press Ctrl + Shift + E or click on Explorer icon on the left sidebar of VS Code. Do you see the directory open?
Now, let us stop the VS Code process.
- List out the processes running in the system and see if anything matches code.
PS> Get-Process | grep code
- If you want the PowerShell way of doing it, run the following command and note the name in the ProcessName column:
PS> Get-Process *code*
- PowerShell deals with objects; grep outputs text. Therefore, now that we know that the exact name of the process is code, we directly get details on the process.
PS> Get-Process code
That gives us a valid output.
- Stop all the code processes.
PS> Stop-Process code
That would not work; the cmdlet accepts a System.Diagnostics.Process object as input.
- Enclose Get-Process within parentheses and pass the input to Stop-Process.
PS> Stop-Process (Get-Process code)
- Now, see if there is a code process running any more.
PS> Get-Process code
The best way of stopping a process is using its ID.
- I am running dconf-editor on my PC right now, and would like to close it. You may choose any process to stop; play safe, though.
PS> Get-Process dconf-editor
PS> Stop-Process -Id 20608