Page 1 of 1

System()/exec() function problem - solved

Posted: Thu Mar 08, 2007 7:43 am
by seth.7
I am trying to use system/exec functions to call a dictionary program. It uses external files with inflections definitions etc. It appears that php is loading the file in a temp directory, since the program returns :
There is no INFLECTS.SEC file. The program cannot work without one. Make sure you are in the subdirectory containing the files for inflections, dictionary, addons and uniques.
(it is there)

Everything is in the php folder, safe mode is (obviously) off. (I have read about the security issues with these functions, but am just trying to get things going first).

Code: Select all

<?php
system('words.exe -deus');
?>
Apache 2, PHP 5, Win XP

How can I get around This? I even tried (for reasons of curiosity only) copying all files to the windows temp directory. no dice.

Thanks, Seth

Posted: Thu Mar 08, 2007 8:35 am
by dude81
check the path where you script is getting executed using functions realpath or pathinfo function then use chdir(this works on linux, tested, should be tested on windows) command

Posted: Thu Mar 08, 2007 8:44 am
by feyd
Programs typically check in the current working directory for their files. If the software isn't written to take advantage of certain operating system features such as path searching, that can mean it won't find the file that may be there normally.

getcwd(), chdir(), realpath() and some other file system functions may all be of interest.

Posted: Thu Mar 08, 2007 9:19 am
by seth.7
Using getcwd worked. It turns out that the program is being executed from the directory the latindict.php file is in, not php.exe, even though it is actually stored in the php program folder. Thanks!