我在我的mac中安装了azure-cli,我可以成功地执行来自cli的所有azure命令。我想在java应用程序中做同样的事情。我看过使用REST端点和azure-的例子。但是我想要的是直接从java执行azure-cli命令。
我尝试从一个java程序中运行'azure登录‘,但是我得到了以下错误。
无法运行程序"azure":error=2,没有这样的文件或目录
发布于 2016-07-06 20:43:45
问题在于缺乏路径变量。如果您想享受命令行中的“查找命令”功能,需要在Java程序中以某种方式设置它:从环境导入路径变量,在您正在编写的代码中设置它,或者任何满足您需要的混合操作。
给出绝对(完整)路径是最可靠的方法,但您可能不希望在源代码中读取如此长的命令名。
发布于 2016-07-11 06:05:13
@harshithabt根据我的经验,这个问题是由命令azure无法在PATH中列出的目录中搜索引起的。有两种方法可以解决在Java中运行命令的问题,请参阅下面。
PATH (或~/.bashrc)设置环境变量~/.profile。- If you command `export PATH=<your-node-path>/bin:$PATH` in a shell session, you only run the Java program with azure command in the current shell session, even run via the Java IDE which must be opened in the current shell session (it means you should open Eclipse via command `<your-ide-path>/eclipse`).
- If you configure the files `~/.profile` or `~/bashrc` to add the node runtime as below, please make sure the configuration files have been reloaded via command `source ~/.profile` in a current session or restart sessions via logout & login or reboot.
PATH中列出的dirs中,例如/bin。只需运行以下命令即可。
-s /bin/节点/bin/节点/bin/节点-s /bin/azure /bin/azure然后,您可以成功地从Java运行azure命令。
https://stackoverflow.com/questions/38189665
复制相似问题