note 85794 modified in function.exec by danbrown
| From: | danbrown@php.net | Date: | Thu, 18 Sep 2008 13:06:10 +0000 |
| Subject: | note 85794 modified in function.exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144509@lists.php.net to get a copy of this message | ||
<?php
function _exec($cmd)
{
$WshShell = new COM("WScript.Shell");
$cwd = getcwd();
if (strpos($cwd,' '))
{ if ($pos = strpos($cmd, ' '))
{ $cmd = substr($cmd, 0, $pos) . '" ' . substr($cmd, $pos);
}
else
{ $cmd .= '"';
}
$cwd = '"' . $cwd;
}
$oExec = $WshShell->Run("cmd /C \" $cwd\\$cmd\"", 0,true);
return $oExec == 0 ? true : false;
}
?>
capture output using ob_start() if you like. Extra code looks for spaces and adds quote marks as
they are needed
--was--
function _exec($cmd)
{
$WshShell = new COM("WScript.Shell");
$cwd = getcwd();
if (strpos($cwd,' '))
{ if ($pos = strpos($cmd, ' '))
{ $cmd = substr($cmd, 0, $pos) . '" ' . substr($cmd, $pos);
}
else
{ $cmd .= '"';
}
$cwd = '"' . $cwd;
}
$oExec = $WshShell->Run("cmd /C \" $cwd\\$cmd\"", 0,true);
return $oExec == 0 ? true : false;
}
capture output using ob_start() if you like. Extra code looks for spaces and adds quote marks as
they are needed
http://php.net/manual/en/function.exec.php