All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.shoothzj.javatool.util.ShellUtil Maven / Gradle / Ivy
package com.github.shoothzj.javatool.util;
import com.github.shoothzj.javatool.module.ShellResult;
import lombok.extern.slf4j.Slf4j;
import java.io.InputStream;
@Slf4j
public class ShellUtil {
public static ShellResult executeCmd(String[] cmd) {
log.info("exec command {}", cmd);
String inputContent = "";
String errorContent = "";
int ret = -1;
try {
Process pid = Runtime.getRuntime().exec(cmd);
ret = pid.waitFor();
InputStream inputStream = pid.getInputStream();
InputStream errorStream = pid.getErrorStream();
inputContent = IOUtil.read2String(inputStream);
errorContent = IOUtil.read2String(errorStream);
log.error("command is {}, result is {}, input content is [{}], error content is [{}]"
, cmd, ret, inputContent, errorContent);
return new ShellResult(ret, inputContent, errorContent);
} catch (Exception e) {
log.error("Execute command exception. [{}], input content is [{}], error content is [{}]"
, e.getMessage(), inputContent, errorContent);
return new ShellResult(ret, inputContent, errorContent, e);
}
}
public static ShellResult executeCmd(String cmd) {
log.info("exec command {}", cmd);
String inputContent = "";
String errorContent = "";
int ret = -1;
try {
Process pid = Runtime.getRuntime().exec(cmd);
ret = pid.waitFor();
InputStream inputStream = pid.getInputStream();
InputStream errorStream = pid.getErrorStream();
inputContent = IOUtil.read2String(inputStream);
errorContent = IOUtil.read2String(errorStream);
log.error("command is {}, result is {}, input content is [{}], error content is [{}]"
, cmd, ret, inputContent, errorContent);
return new ShellResult(ret, inputContent, errorContent);
} catch (Exception e) {
log.error("Execute command exception. [{}], input content is [{}], error content is [{}]"
, e.getMessage(), inputContent, errorContent);
return new ShellResult(ret, inputContent, errorContent, e);
}
}
}