如何在java程序中运行unix enq命令

时间:2013-05-06 13:34:43

标签: java unix

这是用于将文件添加到队列的unix命令。

enq -P QueueName:PrinterName FileName

是否可以使用java运行上述命令。

2 个答案:

答案 0 :(得分:4)

是的,可以使用ProcessBuilder

ProcessBuilder builder = 
           new ProcessBuilder("enq", "-P", "QueueName", "FileName");
Process process = builder.start();
InputStreamReader streamReader = new InputStreamReader(process.getInputStream());
BufferedReader reader = new BufferedReader(streamReader);
String line;
while ((line = reader.readLine()) != null) {
   System.out.println(line);
}

请参阅:enq syntax

答案 1 :(得分:0)

Process p = Runtime.getRuntime().exec(new String[]{"enq", "-P", "QueueName:PrinterName FileName"});