Вопрос:

Automating google cloud SDK installation on windows, GCLOUD is not recognized as an internal or external command

windows batch-file google-cloud-platform gcloud

609 просмотра

1 ответ

50 Репутация автора

I am using following batch file to download and unzip the google-cloud-sdk,

file name: download.bat

set home=%USERPROFILE%
echo %home%
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "(New-Object Net.WebClient).DownloadFile('https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-179.0.0-windows-x86_64-bundled-python.zip', '%home%/google-cloud-sdk.zip');& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%home%/google-cloud-sdk.zip', '%home%/google-cloud-sdk'); }"

and I am using following batch file to install the SDK silently on windows,

file name: install_win.bat

call %USERPROFILE%\google-cloud-sdk\google-cloud-sdk\install.bat --path-update=true --usage-reporting=false --command-completion=false

After these steps are completed successfully when I try to authorize my serice account from another batch file using the following command,

gcloud auth activate-service-account --key-file {json fila path}

It fails and tells me that the glcoud is not recognized internal or external command.

Can anyone please help me solve this error? I think the error is because of the lack of environment variable in windows with the bin file of SDK. How to set that from the batch file?

Автор: Nachiket Joshi Источник Размещён: 08.11.2017 11:56

Ответы (1)


0 плюса

63412 Репутация автора

Решение

The ...cloud...\install.bat routine is called, hence it inherits the calling routine's environment. It does not communicate any changes back to the calling routine.

Since I'd assume that the install.bat is supplied by a 3rd party, hence cannot be altered, then you would need to retrieve the new path for the current cmd instance.

call %USERPROFILE%\...\install.bat ...
FOR /f "delims=" %%a IN ('echopath') DO SET "newpath=%%a"

where echopath.bat is simply one line:

echo %path%

Provided echopath.bat is reachable - and it must be a separate file, not an internal routine - the new path should be returned (to newpath in this instance - I'll let you guess what changes you'd need to make to change that to path...)

Since executing an external batch loads the environment anew, the modified environment path will be reported by echopath and hence assigned to the variable nominated.

Автор: Magoo Размещён: 09.11.2017 12:36
Вопросы из категории :
32x32