Page 1 of 2
executing a command with PHP in windows
Posted: Wed Jan 15, 2003 4:04 pm
by fujiwara takumi
whats the syntax like for executing a command? i have a script on a slave drive i need to be able to access another file on another drive on the same computer via the web. is it possible?
Posted: Wed Jan 15, 2003 4:13 pm
by volka
Posted: Wed Jan 15, 2003 4:18 pm
by fujiwara takumi
thanks, my kraut eating brother! heres my problem, when i run some script i wrote i get the confirmation no "1" back meaning it was succesful but the changes it was to make didnt work. i did this, can you tell me whats wrong with it?
<?
echo "test adding user...";
system("cmd /c cd c:\program files\serv-u", $test1);
system("cmd /c servuadm.exe -ma -ujubbajoo -ppassword", $test2);
echo $test1 . ", " . $test2 . ".<br>";
echo "test complete, check for new user, jubbajoo";
?>
im still fiddling, so laugh it it makes you feel good. me noob to higher PHP type code.
Posted: Wed Jan 15, 2003 4:36 pm
by volka
I doubt
1 means success, normally it's a return value of 0.
Each
system-call stands for itself. Your second command has nothing to do with the first (+you're opening a new command-processor for each with cmd /c

).
try
Code: Select all
echo system("c:\\program files\\serv-u\\servuadm.exe -ma -ujubbajoo -ppassword", $retval), ' ', $retval;;
instead
Posted: Wed Jan 15, 2003 4:40 pm
by fujiwara takumi
*hug*
thanks, ill try that.
next time youre in milwaukee ill buy you a beer!
Posted: Thu Jan 16, 2003 1:46 am
by fujiwara takumi
eh, ok, it didnt work. any idea how i find out what errors were reported?
Posted: Thu Jan 16, 2003 2:27 am
by volka
maybe by using exec() and sneaking up to it

Code: Select all
<pre><?php
$out = array();
exec("dir", $out);
print_r($out);
$out = array();
exec("dir c:", $out);
print_r($out);
$out = array();
exec("dir c:\\program files\\serv-u", $out);
print_r($out);
$out = array();
exec("dir c:\\program files\\serv-u\\servuadm.exe", $out);
print_r($out);
$out = array();
exec("c:\\program files\\serv-u\\servuadm.exe -ma -ujubbajoo -ppassword", $out);
print_r($out);
?></pre>
Posted: Thu Jan 16, 2003 10:04 am
by fujiwara takumi
here are the results of that trial:
new testArray ( [0] => Volume in drive D is WEBROOT [1] => Volume Serial Number is 386E-1AD9 [2] => [3] => Directory of d:\AUBURNSKIES\rs\customermanagement [4] => [5] => 01/01/2003 03:40a
. [6] => 01/01/2003 03:40a
.. [7] => 01/01/2003 03:40a 375 queries.php [8] => 01/16/2003 10:00a 1,533 ftpadmintest.php [9] => 2 File(s) 1,908 bytes [10] => 2 Dir(s) 3,283,456,000 bytes free )
Array ( )
Array ( )
Array ( )
Array ( )
done
, 0
test complete, check for new user, jubbajoo
Posted: Thu Jan 16, 2003 10:56 am
by volka
then even
exec("dir c:\\", $out); failed (the second array is empty) ?
very strange. And where does
done
, 0
test complete, check for new user, jubbajoo
come from?
Posted: Thu Jan 16, 2003 10:57 am
by fujiwara takumi
your quote is just extraneous code i forgot to comment out.
Posted: Thu Jan 16, 2003 11:03 am
by volka
But the questions remains: Why can't it even perform a simple dir c:\ ?
have you restricted permissons for accessing c:\ for the account your webserver/php-script is running at?
Posted: Thu Jan 16, 2003 11:09 am
by fujiwara takumi
could it be that i have like drive traversing turned off in the PHP.ini? is that possible?
or should i peak around in IIS?
its VERY possible i restricted that sort of access, BUT, my SQL database runs off that drive...but i think that the sqlAdmin utility i use to access that database runs off the C drive cuz for some reason it wouldnt run off of d. i wonder if i should try moving the scripts to the c drive and exec' them from there.
Posted: Thu Jan 16, 2003 11:12 am
by volka
php.ini wrote:;
; Safe Mode
;
safe_mode = Off
; open_basedir, if set, limits all file operations to the defined directory
; and below. This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file.
;
;open_basedir =
these are the only two settings I know of having an effect on this (which doesn't mean there are more

)
Posted: Thu Jan 16, 2003 11:19 pm
by fujiwara takumi
i just moved the script to the C drive to try and execute it from there:
new testArray ( )
Array ( )
Array ( )
Array ( )
Array ( )
now im not even traversing the drive. me confused.
Posted: Fri Jan 17, 2003 12:57 am
by fujiwara takumi
i moved the FTP server to the d drive, re wrote the script and it works fine. something is keeping me from running commands on the c drive...some feature...some where. ive poked and poked but i sure cant find it.