executing a command with PHP in windows

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

fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

executing a command with PHP in windows

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post by fujiwara takumi »

*hug*

thanks, ill try that.

next time youre in milwaukee ill buy you a beer!
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post by fujiwara takumi »

eh, ok, it didnt work. any idea how i find out what errors were reported?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post by fujiwara takumi »

your quote is just extraneous code i forgot to comment out.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;) )
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

Post 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.
fujiwara takumi
Forum Newbie
Posts: 10
Joined: Wed Jan 15, 2003 4:04 pm
Location: racine, wi
Contact:

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