为什么我无法使用批处理文件连续为gcloud运行2个命令 [英] Why can't I run 2 commands consecutively using batch file for gcloud

查看:195
本文介绍了为什么我无法使用批处理文件连续为gcloud运行2个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个 .bat 文件:

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

在第一次 gcloud 命令,它会突然使命令提示符中途崩溃,但是当我手动将每行复制并粘贴到命令提示符中与我要尝试的位置相同的位置时 cd.bat 文件,它可以工作...知道为什么吗?顺便说一句,我在Windows 10上.

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.

在Google上进行搜索时,我发现了两个相关的问题,分别在 Github Stackoverflow .

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

Github的解决方案使用的是我不需要的python,而Stackoverflow的解决方案没有人帮助他/她...

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

谢谢

推荐答案

在运行某些gcloud命令时,他们期望它们可能与用户进行交互.此外,它们可能与当前的命令行处理器(Windows上的CMD)产生不利的交互作用.这可能会导致命令行处理器过早结束.一种解决方案是在自己的本地/嵌套命令行处理器实例中运行脚本化的gcloud命令.

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.

今天,您的脚本包含:

gcloud ... some command parameters ...

替换为:

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

这将导致gcloud命令在其自己的嵌套环境中运行,而该环境不会干扰顶层(脚本化)环境.

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

这篇关于为什么我无法使用批处理文件连续为gcloud运行2个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆