By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

Lpr $varname not working

P: 123
Hey all,
I am trying to execute lpr command from PHP script using sell_exec .
If I write like below
Expand|Select|Wrap|Line Numbers
  1. $fin = shell_exec( "lpr -Pprinter1 $str");
Its working fine
But in my application user can specify the printer name so , It should store the value of printer name in one variable i.e $pname and then print it like below,
Expand|Select|Wrap|Line Numbers
  1. $fin = shell_exec( "lpr -P $pname $str");
But I am not sure whether variable name is working with -Ppname ??
Oct 7 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 5,058
You could try doing something more like this:
Expand|Select|Wrap|Line Numbers
  1. shell_exec("lpr -P{$name} {$str}");
Oct 7 '08 #2

Expert 5K+
P: 5,821
Heya, AJD.

Consider using escapeshellarg() to prevent anything... unexpected (

You'd probably need to include the parameter in the arg:
Expand|Select|Wrap|Line Numbers
  1. $safedPName = escapeshellarg("-P{$pname}");
Oct 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.