Instead of running the command directly, wrap it in cmd /C
exec('cmd /C ver 2>&1', $out, $code);
or you can try escaping it
exec('ver ^2^>^&1', $out, $code);
or try
try shell_exec()