I'm writing a script that is trying to install CUDA and set environment variable. As result, it also should check that CUDA is installed successfully. As this check, I run nvcc -V
to get compiler version. Unfortunly, for some reason it doesn't work until I open another shell window. But I strongly need exactly that behaviour, because I have to actually run nvcc
in the same session.
Here is my script:
param([Parameter(mandatory=$true)][string] $FileName)
$VERSION = "9.1"
$argumentList = "-s nvcc_$VERSION cublas_$VERSION cublas_dev_$VERSION cufft_$VERSION cufft_dev_$VERSION npp_$VERSION npp_dev_$VERSION"
$envPath = ";%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v$VERSION\bin;%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v$VERSION\libnvvp";
Write-Host "Install CUDA from $FileName with argumentList $argumentList"
Start-Process -FilePath $FileName -ArgumentList $argumentList -Wait
#adding CUDA to PATH
[Environment]::SetEnvironmentVariable("Path", $env:Path + $envPath, [EnvironmentVariableTarget]::Machine)
#updating PATH for current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
#trying to run something
nvcc -V
But it shows an error
The term 'nvcc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
How can it be done?
PS C:\Users\SOLO> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.98
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.98
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1