在php中,我有两个类似的命令(我的wesite在ubuntu操作系统上运行):cmd1:
exec("tmp=123");cmd2:
$test = exec('echo $tmp');为什么cmd2不知道:$tmp。我怎样才能在cmd 1中捕获$tmp,非常感谢
发布于 2017-03-15 22:52:54
exec在自己的环境中执行外部程序,该环境在进程结束后不再存在,如果您希望将环境变量传递给外部程序,则需要使用putenv对其进行设置,例如:
putenv('tmp=123'); $test = exec('echo $tmp');
这种用法很奇怪,你可能想重新考虑你的设计。
https://stackoverflow.com/questions/42813051
复制相似问题