System()/exec() function problem - solved

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seth.7
Forum Newbie
Posts: 4
Joined: Thu Mar 08, 2007 7:33 am

System()/exec() function problem - solved

Post 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
Last edited by seth.7 on Thu Mar 08, 2007 9:20 am, edited 1 time in total.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
seth.7
Forum Newbie
Posts: 4
Joined: Thu Mar 08, 2007 7:33 am

Post 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!
Post Reply