azure - 如何获取 RunCommandResult 以确定是否有错误?
问题描述
当远程执行具有以下源代码的 Azure Liunux 虚拟机的 shell 脚本并且退出代码不是时,是否可能引发异常0
?
public static void main(String[] args) {
String subscriptionId="";
AppServiceMSICredentials appServiceMsiCredentials = new
AppServiceMSICredentials(AzureEnvironment.AZURE);
Azure azure = Azure
.configure()
.withLogLevel(LogLevel.NONE)
.authenticate(appServiceMsiCredentials)
.withSubscription(subscriptionId);
final String rgName1 = "testlinux_group";
final String linuxVMName = "testlinux";
try {
VirtualMachine virtualMachine = azure.virtualMachines().getByResourceGroup(rgName1, linuxVMName);
System.out.println("Running Command");
List<String> commands = new ArrayList<>();
commands.add("echo 1");
RunCommandInput runParams = new RunCommandInput()
.withCommandId("RunShellScript")
.withScript(commands);
RunCommandResult runResult = azure.virtualMachines().runCommand(virtualMachine.resourceGroupName(), virtualMachine.name(), runParams);
for (InstanceViewStatus res : runResult.value()) {
context.getLogger().info("code : " + res.code());
context.getLogger().info("status : " + res.displayStatus());
context.getLogger().info("message : " + res.message());
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
System.out.println("final");
}
解决方案
推荐阅读
- python - 使用 if 子句和 diff() 应用/Lambda
- oracle - 云上的 DBA 实践
- python - 如何让我的 Anaconda 环境“识别”/激活 anaconda/envs/envname/lib 中的 .so 文件?
- c# - 无法在 Worker 服务中加载程序集(.Net Core3.1 和 NLog 4.9.2)
- javascript - 如何在 div 中动态创建 div 标签 tinyMCE
- python - 检查是否打印了 Python
- node.js - 使用 npm 或 npx 创建反应应用程序时出错
- google-apps-script - Google Script/sheets - 如何使用 ...new Set() 使脚本在循环期间运行得更快
- ruby-on-rails - PDFTK - 使用 Adobe PDF 条形码表单域生成 QrCode
- c# - 结合两个队列产生奇怪的结果