PDA

View Full Version : [ubuntu] php shell exec command



lgastmans
May 19th, 2008, 05:41 AM
Hi guys,

I am desperately trying to get this command to work: It should print the file <filename> to a dot matrix printer. When I run the command directly in the shell it works fine. The file is created in the /tmp folder.

$res = shell_exec("sudo /usr/bin/lpr <filename> -oraw");

$res is blank, and nothing happens (ie printer does not react).
I have tried it like this too:

$res = shell_exec("sudo -U<username> -p<password> /usr/bin/lpr <filename> -oraw");

but does not work either.

I added the following line:
www-data ALL= NOPASSWD: /usr/bin/lpr -<username>
but that did not do the trick.

Any feedback would be greatly appreciated

solcott
May 19th, 2008, 02:57 PM
Give this a try:

$res = system("sudo /usr/bin/lpr <filename> -oraw");

Dr Small
May 19th, 2008, 03:27 PM
Or try using backticks instead:

$res = `sudo /usr/bin/lpr <filename> -oraw`;