Skip to content

Instantly share code, notes, and snippets.

@michael34435
Created October 20, 2014 09:55
Show Gist options
  • Save michael34435/47a6254c6e824d749308 to your computer and use it in GitHub Desktop.
Save michael34435/47a6254c6e824d749308 to your computer and use it in GitHub Desktop.
improved utf8_exec with hstart
<?php
function utf8_exec($cmd, &$output = null, &$return = null, $shell = false, $prefix = "")
{
$cmd = "chcp 65001\r\n$cmd\r\n";
$tempfile = PATH_APP . "/cache/" . "php_exec$prefix.bat";
if (!$shell)
$cmd = preg_replace("/(\\\|\/){1,}/", "\\\\\\", $cmd);
file_put_contents($tempfile, $cmd);
$tempfile = realpath($tempfile);
if (!$shell) {
exec("CALL \"$tempfile\"", $output, $return);
$output = array_slice($output, 10);
@unlink($tempfile);
} else {
exec("hstart /NOCONSOLE /HIGH \"$tempfile\"");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment