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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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