[英]PHP exec using LP command fails on Mac OS X
I am trying to spool a file to a printer attached to the server using PHP. 我正在尝试使用PHP将文件后台处理到连接到服务器的打印机上。
I send a command such as lp -d 'Brother_QL-570' '/Users/user_name/Documents/wwwroot/mmsprint/mmsUw8Vv9
using EXEC in PHP and get a return value of 5
. 我在PHP中使用EXEC发送了
lp -d 'Brother_QL-570' '/Users/user_name/Documents/wwwroot/mmsprint/mmsUw8Vv9
这样的命令,并获得了5
的返回值。 The command works fine in the terminal window. 该命令在终端窗口中可以正常工作。
If I send ls
, whoami
etc, the command executes fine. 如果我发送
ls
, whoami
等,则命令执行正常。
whoami
and ls
live in /bin, so I created a symbolic link for lp and that made no difference. whoami
和ls
居住在/ bin中,所以我为lp创建了一个符号链接,但这没什么区别。
Also tried /usr/bin/lp
and that did not work either. 还尝试了
/usr/bin/lp
,但也没有用。 I'm pulling what little hair I have left out over this. 我正在拉扯掉我遗留的那根小头发。
Safe mode is off. 安全模式已关闭。 The path variables are the same between PHP and my terminal environment.
PHP和我的终端环境之间的路径变量相同。 I am running MAMP on Lion.
我正在Lion上运行MAMP。
FWIW, the command cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570
FWIW,命令
cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570
cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570
has a return value of 133
. cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570
的返回值为133
。
This is my code: 这是我的代码:
$temp_file = tempnam("./", 'mms');
$pdf->Output($temp_file, "F");
$pdf->Close();
$cmd = "lp -d 'Brother_QL-570' '".$temp_file."'";
exec($cmd,$output,$retval);
error_log("-----cmd=".$cmd."\n", 3, "printCard.log");
foreach ($output as $a) {
error_log("-----output=".$a."\n", 3, "printCard.log");
}
error_log("-----retval=".$retval."\n", 3, "printCard.log");
Any thoughts? 有什么想法吗? What am I missing?
我想念什么? This should be easy.
这应该很容易。 Argh!!
啊!
It turns out to be a problem with MAMP. 事实证明这是MAMP的问题。 I googled "MAMP exec fails" and came up with several good answers.
我用谷歌搜索“ MAMP exec失败”,并提出了几个好的答案。 Its a compatibility problem with libraries.
它与库的兼容性问题。 I added
DYLD_LIBRARY_PATH='' &&
to the command and Bob's my uncle. 我在命令中添加了
DYLD_LIBRARY_PATH='' &&
,而Bob是我的叔叔。 Thanks for the replies. 感谢您的答复。
I found a similar solution to the one mentioned about using DYLD_LIBRARY_PATH='' &&
. 我找到了与提到的使用
DYLD_LIBRARY_PATH='' &&
解决方案类似的解决方案。 Using this worked for me, so I tried to find a more permanent fix than including this in all my code. 使用此方法对我来说很有效,因此我尝试找到一种比将其包含在我的所有代码中更永久的修复方法。 I opened up the file
/Applications/MAMP/Library/bin/envvars
and commented the following two lines out: 我打开文件
/Applications/MAMP/Library/bin/envvars
并注释了以下两行:
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
After restarting apache, this is working GREAT! 重新启动apache后,此工具已成功运行! Not sure why this is happening to me though.
我不确定为什么会这样。 Might have to do something with the fact that I am running 2 virtual hosts.
可能与我正在运行2个虚拟主机有关。
What is the output from the command? 命令的输出是什么?
Most likely the PHP user (apache probably) has no permission to print things. PHP用户(可能是Apache)很可能没有打印内容的权限。 Add that user to the lp group.
将该用户添加到lp组。 (Assuming macs work similar to unix in this.)
(假设macs在此类似于unix。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.