PHP exec()命令:如何指定工作目录? [英] PHP exec() command: how to specify working directory?
本文介绍了PHP exec()命令:如何指定工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本,我们称它为execute.php,需要启动一个位于Scripts子文件夹中的shell脚本.必须执行脚本,以便其工作目录为脚本.如何在PHP中完成此简单任务?
My script, let's call it execute.php, needs to start a shell script which is in Scripts subfolder. Script has to be executed so, that its working directory is Scripts. How to accomplish this simple task in PHP?
目录结构如下:
execute.php
Scripts/
script.sh
推荐答案
您可以在exec命令(exec("cd Scripts && ./script.sh")
)中更改为该目录,或者使用
Either you change to that directory within the exec command (exec("cd Scripts && ./script.sh")
) or you change the working directory of the PHP process using chdir()
.
这篇关于PHP exec()命令:如何指定工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文