gpt4 book ai didi

java - 通过JAVA执行Fabric脚本

转载 作者:太空宇宙 更新时间:2023-11-04 13:11:36 24 4
gpt4 key购买 nike

我有这个简单的 fab 脚本,我想通过 JAVA 执行它:

    from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
env.hosts = ['localhost']

def updatefile():
with shell_env(TERM='vt100'):
with cd('/Users/'):
run("pwd")
run("ls -l")

def execute():
updatefile()

当我从命令行执行此脚本时,它可以工作: fab -f test.py 执行,但我想通过 java 执行。尝试过..

public class ExecuteScript {

@Test
public void testExecuteScript() throws NumberFormatException, IOException{

StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec("fab -f src/test/resources/scripts/test.py execute");
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}

} catch (Exception e) {
e.printStackTrace();
}
System.out.println(output.toString());
}
}

它不起作用..查看了 http://fabric8.io/gitbook/quickstarts.html 中的 java 示例文档链接已损坏。

最佳答案

环境,请确保您正在使用您的环境。我建议你使用virtualenv,看起来像这样:

  1. virtualenv .env(不要在 src 文件夹中执行此操作,如果有的话,它应该是下一个目录,也请不要将其 checkin 源代码管理中)
  2. 源.env/bin/activate

然后安装您的依赖项:

  1. pip install Fabric
  2. >??您还需要什么。

那么这是重要的部分:

./.env/bin/fab -f src/test/resources/scripts/test.py 执行

关于java - 通过JAVA执行Fabric脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33899920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com