Why can't I run 2 commands consecutively using batch file for gcloud

百般思念 提交于 2020-01-15 10:15:17

问题


so I have this .bat file:

@echo off
cd C:\Users\user\Downloads
gcloud auth activate-service-account --key-file=keyFileName.json
gcloud auth print-access-token
pause

During the first gcloud command, it will suddenly crash the command prompt halfway, but when I copy and paste each line manually into command prompt in the same location as the location I am trying to cd to in the .bat file, it works... Any idea why? I am on Windows 10 by the way.

Searching on Google, I found two related issues, on Github and Stackoverflow.

Github's solution was using python which was not what I needed and Stackoverflow's one did not have anyone helping him/her...

Thanks


回答1:


When running some gcloud commands, they have the expectation that they may be interacting with a user. In addition, they can adversely interact with the current command line processor (CMD on Windows). This can result in the command line processor ending prematurely. One solution is to run your scripted gcloud commands in their own local / nested instance of a command line processor.

If today, your script contains:

gcloud ... some command parameters ...

replace this with:

cmd /c gcloud ... some command parameters ...

This will cause the gcloud command to run in its own nested environment which won't interfere with the top level (scripted) environment.



来源:https://stackoverflow.com/questions/59185889/why-cant-i-run-2-commands-consecutively-using-batch-file-for-gcloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!