Jump to content

how to execute windows commands in php?


vapanchamukhi

Recommended Posts

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);
?>

 

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

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.. :shrug:

note.bat is what u gave me if i run that it works though..

 

 

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);

-->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??

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

 

 

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

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>

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.