如何执行任务在phing给定的双引号和单引号


how to execute task in phing given double and single quotes

这是我想执行的命令。

php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');"

这是我尝试在phing

<exec command='php -r "apc_clear_cache(); apc_clear_cache(''user''); apc_clear_cache(''opcode'');"' outputProperty="result" />

这是我得到的

BUILD FAILED
Error reading project file [wrapped: /var/virtual/abc.com/build.xml:171:26: > required]
Total time: 0.2093 seconds

请建议。更新:

我通过编写一个名为RunApcClearCache.sh的bash脚本来运行

解决了这个问题
php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');"

,然后使用./RunApcClearCache.sh

调用bash脚本

如果有更好的方法,我想听听。

我也不愿意为这么简单的事情写一个任务。当然,在exectask中一定有一种方法可以正确地转义双引号。

ping需要有效的XML。在有效的XML中,不能在属性中直接使用"

你需要转义它/使用它的等价实体。有五个预定义实体:

&lt; represents "<"
&gt; represents ">"
&amp; represents "&"
&apos; represents '
&quot; represents "

尝试使用实体而不是字符。因此,在命令属性中使用&quot;而不是"

https://en.wikipedia.org/wiki/XML逃离

试试这个:

<exec command="php -r 'apc_clear_cache(); apc_clear_cache(''user''); apc_clear_cache(''opcode'');'" outputProperty="result" />

不确定是否有效

我将创建一个新任务并在那里执行PHP代码。您也可以编写一个新的php文件,并使用php.

执行该文件。

我也遇到了同样的问题。为了避免shell脚本,我定义了一个特别的任务,它映射相应的框架函数,例如

<adhoc-task name="fileHelper"><![CDATA[
  class FileHelper extends Task {
      private $lib = null;
      private $task = null;
      private $stub = null;
      function setTask($task) {
          $this->task = $task;
      }
      function setStub($stub) {
          $this->stub = $stub;
      }
      function setLib($lib) {
          $this->lib = $lib;
      } 
      function main() {
        $task = $this->task;
    $this->$task();
      }
      function generatePharStub() {
        include_once $this->lib . '/FileHelper.php'; 
        HTMLBuilder'FileHelper::generatePharStub($this->stub);
      }
      function generateIncludes() {
        include_once $this->lib . '/FileHelper.php'; 
        HTMLBuilder'FileHelper::generateIncludelist();
      }
  }
]]></adhoc-task>

可以按以下方式调用:

  <fileHelper lib="${lib}" stub="${stub}" task="generateIncludes" />

在我的例子中${lib}指向库目录。${stub}是生成的phar存根文件