doulian4762 2013-12-22 08:16
浏览 46
已采纳

使用shell_exec执行后台变量无效[关闭]

I used shell_exec command to get parallel execution of php script like this :

    shell_exec("echo \"<?php require_once 'path/to/function.php'; DBTest::function2('f2-2');?>\" | php >/dev/null 2>&1 & ");

This work correct , put in this way I can't use variable,like this:

    shell_exec("echo \"<?php require_once 'path/to/function.php'; $s =25 ; DBTest::function2('f2-2');?>\" | php >/dev/null 2>&1 & ");

it's not execute! Can help ?

  • 写回答

1条回答 默认 最新

  • drzfz9995 2013-12-22 08:45
    关注

    Since your string is in double quotes, your $ gets expanded, before it is passed to shell_exec. See string parsing.

    Escape with a backslash :

     shell_exec("echo \"<?php require_once 'path/to/function.php'; \$s =25 ; DBTest::function2('f2-2');?>\" | php >/dev/null 2>&1 & ");
    

    In the shell, $ is also a special character. I'm not sure if you have to escape it a second time for the shell.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式