Added try/catch for AttachConsole

for non-Windows environments
Added extra checks for console mode