Java中的Runtime类调用linux到/home/nginx/目录下执行hexo g命令
时间: 2023-12-22 15:03:09 浏览: 73
可以使用以下代码:
```
String command = "hexo g";
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", command);
processBuilder.directory(new File("/home/nginx/"));
Process process = processBuilder.start();
// 获取命令输出
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
```
需要注意的是,在Linux系统中,需要使用bash来执行命令,并且需要将工作目录设置为/home/nginx/。
阅读全文