當我試圖用Java執行它時,SED命令沒有執行,而手動執行成功。沒有迴應&在輸出中看不到錯誤。java sed命令沒有產生響應
我的SED命令: 手動:
sed -i 's/abc/xyz/' /home/tmp.txt
在java中的文件:
String[] cmdtest = {"sed ", "-i","'s/abc/xyz/'"," /home/tmp.txt"};
過程:
StringBuffer output = new StringBuffer();
Process p = null;
try {
p = Runtime.getRuntime().exec(cmdtest);
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();
}
'sed的-i'不產生任何輸出,你有什麼期待看到? –