vapanchamukhi Posted February 23, 2010 Share Posted February 23, 2010 I want to execute windows commands such as dir,md,move etc.... is this possible?? if yes please help me.... Thanks in advance Quote Link to comment Share on other sites More sharing options...
Alex Posted February 23, 2010 Share Posted February 23, 2010 Take a look at exec Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 actually the exec() doesnot execute the windows commands though.. Quote Link to comment Share on other sites More sharing options...
trq Posted February 23, 2010 Share Posted February 23, 2010 actually the exec() doesnot execute the windows commands though.. Um, yes it does. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 i have been trying this but it does not seem to work.. any help would be appreciated. i know i need to start a new thread for this.. but i stopped trying this so just wanted to see how to execute the commands of windows. one more thing is i gave full permissions to all users to the windows/system32 folder.. but nothing works though.. <?php $command1 = 'notepad.exe'; exec($command1); ?> Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 make a notepad.bat file and place it in a non system dir, say c:\php_commands windows is real funny about letting anything non OS related exec anything from the system dirs and have the notepad.bat look like this @echo off start c:\windows\system32\notepad.exe exit Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 hai jay no luck though.. <?php $command = 'cd "D:\test123"'; echo exec($command); $command1 = 'note.bat'; exec($command1); ?> <INPUT type="submit" value="Run Automation" onclick="<?php echo exec($command1); ?>" /> nothing just happens.. note.bat is what u gave me if i run that it works though.. Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 make sure the permissions to the bat has everyone with full access, also make sure that teh account you are on has log on as service privledges Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 i gave full permissions to the file and also i am administrator in my machine and i have full previlages. still could not able to figure out why is that not working.. :-\ Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 hmm got me ... i used your code and my bat file and it worked Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 can any one try to explain y?? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 23, 2010 Share Posted February 23, 2010 Why would you even want php to open notepad? Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 umm to have fun with visitors?? honestly im not sure a question was asked i just tried to help resolve it is all. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 23, 2010 Share Posted February 23, 2010 You do realise, that it tries to open notepad on SERVER not on visitor's computer? Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 oh i know that ... not sure if they do ....was asuming they were on the server directly .... Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 23, 2010 Share Posted February 23, 2010 So anyway: this: <?php $command1 = 'notepad.exe'; exec($command1); will work when you run it from CLI, when you run it from browser however it doesn't make any sense. Try something like <?php $command1 = 'type c:\autoexec.bat'; exec($command1,$output); var_dump($output); Quote Link to comment Share on other sites More sharing options...
vapanchamukhi Posted February 23, 2010 Author Share Posted February 23, 2010 -->i want to execute commands from webapplication in the sense, for example when he/she gives "dir" command,i want the user to see the files thats been uploaded/created by him/her, as in windows. -->If notepad opens up on the server side, then where the information, stored in that file, will be stored??? Is it prone to security?? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 if u want to see the files on the sevrer then it can be done like this <?php $command1 = 'D:\test123\1.bat'; exec($command1,$output); print_r($output); ?> bat file should be @echo off dir d:\ >much.txt type much.txt exit Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 23, 2010 Share Posted February 23, 2010 Or just <?php $command1 = 'dir d:\\'; exec($command1,$output); print_r($output); [/code] Or <?php $dir = `dir d:\\`; // <-- these are backticks here, not single quotes echo $dir; Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 yes Mchl these things are working fine.. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 23, 2010 Share Posted February 23, 2010 one small issue i have i need to call an exe from my present system but that is not working.. can any one help me hw to open an application.. <?php function callTool ($path,$file) { chdir($path); $call = $path.$file; pclose(popen('start /b '.$call.'', 'r')); } // -- Call tool1 ----- $location = "C:\\Program Files\\fabFORCE"; $filename = "\\DBDesigner4.exe"; callTool($location,$filename); //echo $location.$filename; ?> this is the code i am using.. Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 there is no way that i am aware to open an application client side, if you are trying to just display a text file on a page so that a user can open/edit/save it try something like this, <?php $fn = "file.txt"; $file = fopen($fn, "a+"); $size = filesize($fn); if($_POST['addition']) fwrite($file, $_POST['addition']); $text = fread($file, $size); fclose($file); ?> <form action="<?=$PHP_SELF?>" method="post"> <textarea><?=$text?></textarea><br/> <input type="text" name="addition"/> <input type="submit"/> </form> Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 24, 2010 Share Posted February 24, 2010 i dont want the application to run on the client side i want it to be opened in the server, but this is not happening!! Quote Link to comment Share on other sites More sharing options...
trq Posted February 24, 2010 Share Posted February 24, 2010 Are you using this poorly written function? function callTool ($path,$file) { chdir($path); $call = $path.$file; pclose(popen('start /b '.$call.'', 'r')); } Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 24, 2010 Share Posted February 24, 2010 no it is not abt that function.. i wrote this bat file @echo off "C:\\Program Files\\fabFORCE\\DBDesigner4.exe" exit and this is my code.. <?php $command1 = 'D:\test123\ew.bat'; exec($command1,$output); ?> but nothing seem to work that function was one of the things i got from php.net http://www.php.net/manual/en/ref.exec.php#59361 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.