Forum Moderators: coopster

Message Too Old, No Replies

cannot cd with shell_exec

cd doesn't do anything in shell_exec

         

luong

8:46 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



I have the following script:
$c_path = "/absolute_path_to_some_directory";
$test_cmd = "cd $c_path; ls";
$test_res = shell_exec($test_cmd);

Regardless of where I put the script, when executed, it always lists the contents of the
directory where it is placed, rather than the contents of some_directory. In other words, it appears that cd is not working. I have verified that path and permissions are correct. PHP is version 4.3.9. What's wrong?

Tuan.

bcolflesh

8:52 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[us3.php.net...]

Read the notes at the bottom - reader suggests using chdir:

[us3.php.net...]

luong

2:56 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Thank you. This fixed the problem. However, I have another problem, which is that shell_exec doesn't seem to work either with user commands. In the following script,

$test_cmd1 = "command";
$test_res1 = shell_exec($test_cmd1);
echo $test_res1;

if I use as "command" somethink like "ls", "pwd", it works ok. However, if I use a custom command, (full path) nothing happens. However, if I log on as
a different user (to make sure permissions are OK) and type in the terminal the command (full path), it works OK. I have this problem only on one server, so I assume there is a configuration problem? The command can be as simple as a file containing the line echo "hello"

Tuan.

bcolflesh

7:06 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it works one place and not another, then it's usually an environment/configuration difference on the server - that particular server may have some sort of script jail setup that only allows specific command to be issued by user scripts - in PHP's case, admins may block exec(), passthru() and their ilk - you need to check with the admin.