Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit b8d9ad4

Browse files
author
Michael Grauer
committed
BUG: refs #68. exec function was changing cwd, but not channging back.
1 parent 5f57925 commit b8d9ad4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/KWUtils.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public static function appendStringIfNot($subject, $ext)
141141
*/
142142
public static function exec($command, &$output = null, $chdir = "", &$return_val = null)
143143
{
144+
$currCwd = getcwd();
144145
if(!empty($chdir) && is_dir($chdir))
145146
{
146147
if(!chdir($chdir))
@@ -151,6 +152,11 @@ public static function exec($command, &$output = null, $chdir = "", &$return_val
151152
// on Linux need to add redirection to handle stderr
152153
$redirect_error = KWUtils::isLinux() ? " 2>&1" : "";
153154
exec(KWUtils::escapeCommand($command) . $redirect_error, $output, $return_val);
155+
// change back to original directory
156+
if(!chdir($currCwd))
157+
{
158+
throw new Zend_Exception("Failed to change back to original directory: [".$currCwd."]");
159+
}
154160
}
155161

156162

0 commit comments

Comments
 (0)