How can I run a script that uses cl.exe without Developer PowerShell?

0
3
Asked By CuriousCat42 On

I'm trying to run a script that relies on `cl.exe`, but I've hit a snag—`cl.exe` isn't on the PATH unless I run the script through Developer PowerShell. I want to avoid asking users to launch the script that way. Is there a way to enable the script to access `cl.exe` without relying on Developer PowerShell?

5 Answers

Answered By DevGuru22 On

If you're asking about `cl.exe`, which is part of MSVC, take a look at the batch file that starts the Visual Studio developer environment. You'll find some environment variables being set there. I recommend you replicate this in your PowerShell script. Just setting the path to `cl.exe` might not be enough—you might need other variables that are set when launching from that batch file.

CodeExplainer101 -

Could you clarify if this is specifically related to MSVC?

Answered By CodeNinja88 On

You can directly find the path to `cl.exe` on your system and run it using its full path. A reliable method would be to check the registry for the Visual Studio installation location and then search within that for `cl.exe`. But if you want a quicker solution, try this PowerShell command to find it in the default installation directories:

```powershell
$FilePath = Get-ChildItem 'C:Program Files', 'C:Program Files (x86)' -Recurse -Filter cl.exe | select -First 1 -ExpandProperty FullName
& $FilePath
```

SkepticalWorker99 -

How do I use the registry to find the install location of Visual Studio?

Answered By BatchFileHero On

You could also just grab the batch file that initializes the Visual Studio command prompt, modify it, and run your own version. Just copying that batch file gives you everything set up correctly—any environment variables or settings you might need.

Answered By TechieTom On

Another option is to have users add the `cl.exe` path to their system PATH variable, or just execute it with its full path instead of just calling `cl.exe`. It's a pretty common issue, and you can check out these Stack Overflow links for more background:
- https://stackoverflow.com/questions/4822400/register-an-exe-so-you-can-run-it-from-any-command-line-in-windows
- https://stackoverflow.com/questions/50739853/how-to-retrieve-the-path-to-cl-exe

QuestionerPro -

The challenge with modifying PATH is that I can't know the installed Visual Studio version at runtime.

Answered By LostInTechland On

What exactly is 'Developer PowerShell'? 🤔

ResourceFinder -

It's a specialized PowerShell that comes with Visual Studio; you can find more info here: https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.