21

I tried to compile a program, but the terminal is not opening.

error:The terminal process failed to launch: Starting directory (cwd) "D:\vs code\march long 2020" does not exist.

This guy has the same error, but the pop-up is different link.

Below is the JSON file of my Visual Studio Code:

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "C_Cpp.updateChannel": "Insiders",
    "files.autoSave": "afterDelay",
    "java.saveActions.organizeImports": true,
    "window.zoomLevel": 0,
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.windowsEnableConpty": false,
    "json.schemas": [

    ]
}

See this link for full error description. I wrote code and compiled and got an error message.

Link

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mr. abhi
  • 221
  • 1
  • 2
  • 7

13 Answers13

44

This setting breaks my terminal window (because PowerShell is blocked due company administrative policy):

Enter image description here

Afterwards, I could not open the terminal again.

Restore CMD as default

  • open Preferences > Settings (CTRL+,)
  • search for terminal.integrated.defaultProfile.windows and set a default (for me Command Prompt)

Enter image description here

Now the terminal should open again. This is not a fix to get PowerShell working in Visual Studio Code, just a guide to restore the terminal window.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tom
  • 9,550
  • 6
  • 30
  • 49
3

It appears that you're trying to get PowerShell in a Visual Studio Code integrated terminal.

Let me share the process of how I did it.

  1. Open Visual Studio Code
  2. Go to menu FilePreferencesSettings
  3. Type "Terminal" in the search bar
  4. Under Features, click on "terminal"
  5. Scroll down until you find a section like this and make sure the option is empty (this sets a default starting directory):

Terminal › Integrated: Cwd
An explicit start path where the terminal will be launched, this is used as the current working directory (cwd) for the shell process.
This may be particularly useful in workspace settings if the root directory is not a convenient cwd.

  1. Scroll down until you find this other option

Terminal › Integrated › Shell: Windows
The path of the shell that the terminal uses on Windows (default:

  1. Click on edit settings.json

  2. Paste your terminal absolute path within the brackets (make sure you escape the slashes). That's the reason of why I'm using double

"terminal.integrated.shell.windows": "C:\\InstallationDirectory\\PowerShell\\7\\pwsh.exe"

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Edward Casanova
  • 726
  • 7
  • 19
1

I also faced the same issue, but I was not able to find a solution.I got a different fix for that..

  1. Install Git Bash. Download link.
  2. Open the settings.json file. change the path of terminal to where you installed Git Bash. i.e., in "terminal.integrated.shell.windows": eg:- "terminal.integrated.shell.windows": "C:\Program Files\Git\git-bash.exe" in my case. NOTE:- the path contains double back slash(\ \).
  3. press Ctrl + `. An external Terminal opens on the current directory.
  4. now compile your code :)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vinod
  • 766
  • 6
  • 11
1

FYI I faced the same issue when I named my parent directory in 3byte characters. Changed the directory name to alphabetical to resolve the issue.

shrskn
  • 33
  • 7
  • What are "3byte characters"? Do you mean [UTF-8](https://en.wikipedia.org/wiki/UTF-8) byte sequences? (E.g., 0xE2 0x80 0x94 for Unicode code point U+2014 ([EM DASH](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128))) – Peter Mortensen Jun 21 '23 at 14:19
1

I had the same issue on my Mac. I solved it by adding

"terminal.integrated.shell.osx": "/bin/bash"

in file settings.json.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jonask
  • 679
  • 2
  • 6
  • 21
1

I had the same issue with VS Code running on Windows connecting to a Linux remote. It probably occurred since during my previous session I deleted a directory on the remote and now it was trying to start a shell in this directory. Simply recreating the directory (an empty one) solved the problem for me.

Basileios
  • 285
  • 2
  • 6
0

If you on Windows, before doing any of those steps, try to perform a Full Shut down or Restart.

Press and hold the Shift key and shut down or restart your PC from the start menu.

It helped to get terminal back many times.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

I was getting this error "The terminal process failed to launch: Path to shell executable "C:\Program Files\PowerShell\7\pwsh.exe" does not exist" What i noticed i have not installed powershell 7 as i have installed this error has been resolved

or if we want to continue with same Powershell what we have on our system then we have to change the path By editing the jason file setting>terminal.integrated.shell.windows>Edit in setting.jason enter image description here

comment out "terminal.integrated.shell.windows": "C:\Program Files\PowerShell\7\pwsh.exe", and uncomment "terminal.integrated.shell.windows": "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe", enter image description here

0

I was able to fix this by adding "type": "shell" to the task. It seems that the default is "type": "process" and that wasn't letting the task run. The process type would need the windows/command structure as outlined here: https://code.visualstudio.com/docs/editor/tasks#_operating-system-specific-properties.

tagyoureit
  • 1,276
  • 1
  • 10
  • 17
0

Go to the setting of Visual Studio Code and disable this property powershell.integratedConsole.suppressStartupBanner. It worked for me.I am using VS code version 1.62.3 enter image description here

Sachin
  • 101
  • 1
  • 6
0

Sometimes in Visual Studio Code, its default profile path of the command prompt will be mismatched so for that reason it is unable to launch the terminal.

Solution 1: try correct it with this path: "terminal.integrated.shell.windows": "C:\Windows\System32\cmd.exe".

or

Solution 2:

Enter image description here

Press Ctrl + P to open the settings.json file.

Find the line: terminal.integrated.shell.windows": "C:\Windows\System32\cmd.exe and update with the below configuration,

 "terminal.integrated.profiles.windows": {
        "my-pwsh": {
          "source": "PowerShell",
          "args": ["-NoProfile"]
        }
      },
    //"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Suresh B B
  • 1,387
  • 11
  • 13
0

I really struggled with this issue when creating a new project with Maven and I later realized the issue was with restriction on my profile folder as the machine belongs to the company.

I decided to uninstall Visual Studio Code as by default its usually installed under C:\Users\ProfileName\AppData\Local\Programs\Microsoft VsCode and re-install it as an administrator. Guide to completely install Visual Studio Code is on page How can I uninstall Visual Studio Code completely?

To install Visual Studio Code as administrator you have to download the System Installer version (NOT the default one with a big blue button). Once downloaded, run it as administrator and the installation will be directed to the programs folders as opposed to the user profile folder...enjoy!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
-1

Why is Visual Studio Code terminal failing at launch?

The Visual Studio Code terminal can fail when launching due to the fact that your default terminal was being launched through the properties of the program as an administrator automatically (please, check the hyperlink image below):

Right click PowerShell → Properties → Compatibility → "Run this program as an administrator"

How do I solve it?

If you have this option checked, it's as simple as to uncheck it, apply, and accept.

Please, keep in mind that after you do this, each time in the future that you want to open your terminal it won't be opened anymore as an administrator automatically. You'll have to do it manually by right clicking your program, and selecting the option "Run as Administrator".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    (Despite its weird form, this answer was probably ***not*** plagiarised, [ChatGPT](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned) or otherwise.) – Peter Mortensen Jun 21 '23 at 15:02