PHP不能与shell_exec(),system()或passthru() [英] PHP doesn't work with shell_exec(), system() or passthru()

查看:143
本文介绍了PHP不能与shell_exec(),system()或passthru()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从文件夹中读取最近的文件。找到最新的文件后,我一行一行地读取,并使用条形码打印机打印在条形码打印机上。

I am trying to read the most recent file from the folder. After finding the latest file, I'm reading it line by line and printing it on the barcode printer using barcode Overprinter software. This barcode printer is the default printer on my server.

以下是我的PHP程式码:

Here is my PHP code:

<?php
    $files = glob('C:\barcode\*.*');
    $files = array_combine($files, array_map('filectime', $files));
    arsort($files);
    echo key($files);  // for testing

    $handle = @fopen(key($files), "r");
    if ($handle) {
         while (($buffer = fgets($handle, 4096)) !== false) {
             echo $buffer; // for testing
              $retval=passthru("BarcodeGenerator.exe ".$buffer.",,Code128,0");
// based on http://www.free-barcode.com/CommandLineBarcode.htm
            echo $retval;
         }
            if (!feof($handle)) {
                echo "Error:\n";
         }
         fclose($handle);
    }
    ?>

上述命令行在我的命令行提示符下运行正常,但它不在php脚本中。
程序挂起。什么都没发生。如果我评论passthru线,一切都很好。

The above command line runs fine in my command line prompt but it doesn't in php script. The program hangs. Nothing happens. If I comment the passthru line, everything is fine. The program executes.

以下是我到目前为止尝试过的操作:

Here is what I've tried so far:


  • 检查PHP是否在安全模式下运行。


  • 已关闭Windows防火墙。

  • 我已执行命令 calcs / g BarcodeGenerator.exe everyone:F

  • 我已将可执行文件和相关文件复制到wamp \www文件夹。

  • 我已将UAC设置更改为最小

  • 没有防病毒软件目前在我的系统上运行。

  • 我尝试过 system() shell_exec code> exec()

  • 我已经尝试打开安全模式,并将上述目录放在 safe_mode_include_dir
  • 我尝试用单引号(')替换双引号( )。

  • 我尝试给出完整路径( C:\\wamp\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\

  • Checked whether PHP is running in safe mode. It's not.
  • Turned off Windows Firewall.
  • I have run the command calcs /g BarcodeGenerator.exe everyone:F
  • I have copied the executable and the related files to the wamp\www folder. the above code (bad idea, but I still did it) and redid calcs.
  • I have changed the UAC settings to minimum
  • No antivirus is currently running on my system.
  • I've tried system(), shell_exec() and exec() too
  • I've tried turning safe mode on and putting the above directory under safe_mode_include_dir
  • I've tried replacing double quotes (") with single quotes (').
  • I've tried giving the full path (C:\\wamp\\www\\)

命令在命令提示符下运行良好。

The commands run fine in a command prompt.

所以,有没有办法在PHP下运行 shell_exec 命令作为管理员?它似乎不想运行可执行文件只有这一个)。我在 Windows 7 上运行 WAMP

So, is there any way to run the shell_exec command as administrator under PHP? It doesn't seem to want to run an executable at all (not only this one). I'm running WAMP on Windows 7.

例如, shell_exec('dir')可以正常工作,但 shell_exec('java')

For example, shell_exec('dir') works fine, but shell_exec('java') doesn't. Why not?

推荐答案

因为你不能运行任何可执行文件,如Java,这绝对是一个权限问题。

Since you can't run any executables, like Java, this is definitely a permissions problem. The solution, while not recommended for a production server due to security, is to run your WAMP server as administrator.

请参阅此链接了解有关如何操作的详细信息。

See this link for details on how to do it.

这篇关于PHP不能与shell_exec(),system()或passthru()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆