开发者

Can't run "cd" command in PHP shell_exec()

I recently got my laptop w开发者_运维知识库ith Apache setup on my university's Ethernet connection. Now I can connect to my computer from anywhere as long as I have either the IP address or host name (which I can choose). Now I want to create a Web-based command prompt that will let me run commands on my laptop from any device.

One problem is that I can't run the "cd" command. I have my PHP script setup so it can run a series of commands delimited by a newline character. So I run "cd ../" and then "pwd" but it's still in the root directory of my Web app. How do I fix this?


If you do this:

 shell_exec("cd ..");
 shell_exec("pwd");

Then the second command will be executed with a new shell, which has the same starting directory as the first had, because it's a subprocess of the current PHP.

The changing of the current directory with the first shell exec won't last to the second one. Such a series of depended shell commands only works by executing all at once:

 shell_exec("cd .. ; pwd");


I think you have to change the directory of the current process/script. You do this with chdir. Then you can run shell_exec.

I assume you realize the severe security concerns your solution creates...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜