简体   繁体   中英

How to run unix enq command in java program

Here is the unix command for adding a file to the queue.

enq -P QueueName:PrinterName FileName

Is it possible to run the above command using java.

Yes, it's possible using 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);
}

See: enq syntax

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM