available printers to selectbox, lpstat, console, apache, php, html

1

I have a webserver in a local network (headless Mac-Mini), running a web based POS system. I want to provide a possibility to the regular staff members of the shop, to switch the thermal receipt printer manually from cashier 1 to cashier 2, in case of paper out or other printing problems, with the result, that the customer may leave the shop with the receipt, without needing to wait for changed paper roll (upto 5 mnts.) or arrival of network admin (upto 5 hrs.) :-) The current solution is a selectbox, which is generated like this (simplified for better understanding):

<?php

$printers = exec("lpstat -a | cut -f1 -d ' ' >printer.txt");
$p = file('printer.txt');

$tmp = '<select name="printer" autocomplete="off">';
$tmp .= '<option> --- select printer --- </option>';
foreach($p AS $printer) $tmp .= '<option value="' . $printer . '">' . $printer . '</option>';
$tmp .= '</select>';

echo $tmp;

?>

My question is, how would it be possible to grab the listed printers and build the selectbox without the detour of writing a file which is read by php after. I mean, using the console output (via exec) directly in ONLY ONE LINE, for example by adding a delimiter like ; that the result may be used in a variable like this (will not work, just to explain):

<?php

$printers = exec("lpstat -a | cut -f1 -d ' ' **another option to add the delimiter**");
$p_ary = explode(';', $printers);

... build the selectbox ...

?>

The variable $printers should look like Epson_1;Epson_2;Epson_1_cashier2 ... which must be provided by exec in one single line.

Thanks for your ideas.

ddlab

Posted 2016-08-26T16:37:57.930

Reputation: 111

No answers