Running a batch file that opens a putty terminal by PHP

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

Post Reply
anuragroy007
Forum Newbie
Posts: 1
Joined: Fri Nov 13, 2009 5:26 am

Running a batch file that opens a putty terminal by PHP

Post by anuragroy007 »

I have written a batch file that opens up a command line window(cmd.exe). When i double click the batch file it opens a terminal and works fine. However when i try to run the batch file through the commands exec() and system() of PHP nothing happens. I am using Apache2.2 web server,PHP5 and Firefox/IE browser. Can someone please let me know what I am missing?
The files are as below:
expt.bat
@echo off
cd C:\Documents and Settings\abcdef\Desktop
start putty -ssh -l username -pw passwd 188.172.64.51

experiment.php

<?php
if(isset($_POST['submit']))
{
$arg="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\expt.bat";
system("C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\commandapache.exe",$command_output);
echo("$command_output<br>");
$command="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\commandapache.exe /c $arg";
echo exec("$command 2>&1 && exit",$ret,$err);
echo "ret: ";
echo $ret;
echo "<br/>";
echo "err is ";
echo $err;
} else {
// display the form
?>
<form action="" method="post">
<input type="submit" name="submit" value="DO IT!">
<a href="C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\commandapache.exe"> CLICK HERE </a>
</form>
<?php
}
?>

The error displayed is:
1
operable program or batch file.ret: Array
err is 1
Thanks in advance.
Post Reply