使用重定向時使用的ProcessBuilder我想用的ProcessBuilder運行此命令:如何在Linux中
sort -m -u -T /dir -o output <(zcat big-zipped-file1.gz | sort -u) <(zcat big-zipped-file2.gz | sort -u) <(zcat big-zipped-file3.gz | sort -u)
我曾嘗試以下:
// This doesn't recognise the redirection.
String[] args = new String[] {"sort", "-m", "-u", "-T", "/dir", "-o", "output", "<(zcat big-zipped-file1.gz | sort -u)", "<(zcat big-zipped-file2.gz | sort -u)", "<(zcat big-zipped-file3.gz | sort -u)"};
// This gives:
// /bin/sh: -c: line 0: syntax error near unexpected token `('
String[] args = new String[] {"/bin/sh", "-c", "\"sort -m -u -T /dir -o output <(zcat big-zipped-file1.gz | sort -u) <(zcat big-zipped-file2.gz | sort -u) <(zcat big-zipped-file3.gz | sort -u)\""};
我使用args
這樣的:processBuilder.command(args);
更新了我的問題。我想將幾個zcat命令的輸出重定向到排序。 –
ProcessBuilder不是一個shell。要麼顯式調用shell,要麼自己執行重定向。 – jtahlborn
這不是重複的。這裏的問題是不同的。我在第二次嘗試時明確調用了shell。 –