我正在嘗試使用java爲linux上的raid驅動器創建文件系統。ProcessBuilder拋出異常:Arguement contains =
當我嘗試使用ProcessBuilder執行以下命令時,遇到以下問題。
進程 '[在/ usr /斌/須藤,/sbin/mkfs.ext4,的/ dev/MD0,-m 1,-O uninit_bg,-E lazy_itable_init = 1]' stderr的轉儲命令:mke2fs 1.42。 3 (14月2012)
指定爲選項(S):lazy_ _init
擴展選項由逗號分隔,並且可以採取一個參數 ,其 通過等於襯托('= ') 標誌。
有效的擴展的選項有: 跨距= 條紋寬度= 調整大小= lazy_itable_init = < 0禁用,1啓用> lazy_journal_init = < 0禁用,1啓用> test_fs 丟棄 nodiscard quotatype =
我的ProcessBuilder對象看起來像這樣
mkfs("ext4", "/dev/md0", "-m 1", "-O uninit_bg", "-E lazy_itable_init=1")
public void mkfs(String filesystem, String devicename, String... options) {
mkfsCommand.add(SUDO_CMD);
if(fileSystemType.equals("xfs")){
mkfsCommand.add("/sbin/mkfs.xfs");
} else if (fileSystemType.equals("ext4")) {
mkfsCommand.add("/sbin/mkfs.ext4");
}
mkfsCommand.add(deviceName);
for (String option:options) {
mkfsCommand.add(option);
}
List<String> mkfsCommand = Lists.newLinkedList();
Exec.exec(ProcessBuilder(mkfsCommand))
}
Exec.exec是我用來執行系統命令的庫。我無法改變它,但這是它所做的一小部分。
public String exec(ProcessBuilder pb) {
String cmdString = Arrays.deepToString(pb.command().toArray(new String[0]));
int retval = 0;
Process p = null;
String output = "";
if(shouldLog) {
logger.debug("in exec: " + cmdString);
}
String error = null;
try {
p = pb.start();
if (executionDeadline != null) {
Thread durationEnforcer = new DurationEnforcer(executionDeadline, p);
durationEnforcer.start();
}
Future<String> futureErr = null;
if (!pb.redirectErrorStream()) {
futureErr = SingleExecutor.submit(new StreamReader(p.getErrorStream()));
}
StreamReader outputReader = new StreamReader(p.getInputStream());
p.getOutputStream().close();
output = outputReader.call();
retval = p.waitFor();
if (futureErr != null) {
error = futureErr.get();
}
if (error != null && !error.isEmpty()) {
if(shouldLog) {
logger.warn("Process '" + cmdString + "' stderr dump:\n" + error);
}
}
this.stdOutput = output;
this.stdError = error;
} catch (Exception e) {
logger.warn("exec failed: " + e + "\nstdout:\n" + output);
throw new RuntimeException("exec failed: ", e);
} finally {
StreamHelper.closeStreamsAndDestroy(p);
}
if (retval != 0) {
String msg = "exec failed with " + retval + ": " + cmdString;
if(shouldLog) {
logger.warn(msg + "\nstdout:\n" + output);
}
throw new ExecException(error, cmdString, retval, output);
}
if(shouldLog) {
logger.debug("finished exec: " + cmdString);
}
return output;
}
}
我不知道爲什麼我得到這個錯誤。我懷疑-E lazy_itable_init = 1沒有正確傳遞給Processbuilder。任何想法發生什麼?