Java Runtime.getRuntime().exec不使用gcloud

Java Runtime.getRuntime().exec不使用gcloud,java,google-cloud-platform,gcloud,runtime.exec,Java,Google Cloud Platform,Gcloud,Runtime.exec,我试图描述最后执行的数据流作业,以检查特定的数据流作业是否正在运行、停止、失败或使用java执行 我正在尝试使用Runtime.getRuntime().exec(command) 当我执行此代码时,我得到一个错误,如下所示: Exception in thread "main" java.io.IOException: Cannot run program "gcloud": CreateProcess error=2, The system canno

我试图描述最后执行的数据流作业,以检查特定的数据流作业是否正在运行、停止、失败或使用java执行

我正在尝试使用
Runtime.getRuntime().exec(command)

当我执行此代码时,我得到一个错误,如下所示:

Exception in thread "main" java.io.IOException: Cannot run program "gcloud": CreateProcess error=2, The system cannot find the file specified

有人能帮我解决这个错误吗?

进程
ProcessBuilder
类启动进程

它不运行bashshell命令,但这就是您键入的命令。你不能运行这个

您可以尝试启动bash,并将其作为命令传递给bash执行。不要使用runtime.exec、使用ProcessBuilder、不要将命令作为单个字符串传递、将每个参数作为单独的字符串传递。尝试:

List.of(“/bin/bash”、“-c”、“gcloud……所有这些乱七八糟的东西”)作为命令


我甚至不确定那$(东西是bash、zsh、fish还是什么,确保你启动了正确的shell。

这能回答你的问题吗?[1/2]谢谢你的解决方案。我试过了,但它给了我空值作为输出。所以我试过使用command,它部分工作了
processBuilderList.command(“cmd.exe”,“/c”,“gcloud”,“dataflow”,“jobs”,“list”,“--sort by=CREATION\u TIME”,“--limit=1”,“--format=get(id)”;
实际上,我想把上面的输出传递给下面提到的另一个命令,如果我在bash中运行它,它会工作得很好。当我试图在上面提到的命令中添加“gcloud dataflow jobs description”时,它会给我null。[2/2]这就是我在bash中运行的内容,并给出了正确的输出:gcloud dataflow jobs description$(gcloud dataflow jobs list--sort by=CREATION\u TIME--limit=1--format=“get(id)”--format=json您能建议我如何将两者集成吗?
job\u id=$(gcloud dataflow jobs list--sort by=CREATION\u TIME--limit 1--format=“get(id)”--region=europe-west1)gcloud数据流作业描述$job\u id--format=json
Exception in thread "main" java.io.IOException: Cannot run program "gcloud": CreateProcess error=2, The system cannot find the file specified