diff --git a/src/win32.c b/src/win32.c
index 93cecda..cba57fb 100644
--- a/src/win32.c
+++ b/src/win32.c
@@ -72,13 +72,17 @@ struct _geany_win32_spawn
 	HANDLE hStderr;
 	HANDLE processId;
 	DWORD dwExitCode;
+
+	/* Temp file */
+	HANDLE hStdoutTempFile;
+	HANDLE hStderrTempFile;
 };
 typedef struct _geany_win32_spawn geany_win32_spawn;
 
 static gboolean GetContentFromHandle(HANDLE hFile, gchar **content, GError **error);
 static HANDLE GetTempFileHandle(GError **error);
 static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline, const TCHAR *dir, GError **error);
-static VOID ReadFromPipe(HANDLE hRead, HANDLE hWrite, HANDLE hFile, GError **error);
+static DWORD ReadFromPipe(HANDLE hRead, HANDLE hWrite, HANDLE hFile, GError **error);
 
 
 static wchar_t *get_file_filters(void)
@@ -859,8 +863,8 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
 	geany_win32_spawn gw_spawn;
 
 	/* Temp file */
-	HANDLE hStdoutTempFile = NULL;
-	HANDLE hStderrTempFile = NULL;
+	gw_spawn.hStderrTempFile = NULL;
+	gw_spawn.hStdoutTempFile = NULL;
 
 	gchar *stdout_content = NULL;
 	gchar *stderr_content = NULL;
@@ -892,11 +896,11 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
 
 	if (std_err != NULL)
 	{
-		hStderrTempFile = GetTempFileHandle(error);
-		if (hStderrTempFile == INVALID_HANDLE_VALUE)
+		gw_spawn.hStderrTempFile = GetTempFileHandle(error);
+		if (gw_spawn.hStderrTempFile == INVALID_HANDLE_VALUE || gw_spawn.hStderrTempFile == NULL)
 		{
 			gchar *msg = g_win32_error_message(GetLastError());
-			geany_debug("win32_spawn: Second CreateFile failed (%d)", (gint) GetLastError());
+			geany_debug("win32_spawn: Stderr temp file creation failed (%d)", (gint) GetLastError());
 			if (error != NULL)
 				*error = g_error_new(G_SPAWN_ERROR, G_FILE_ERROR, "%s", msg);
 			g_free(msg);
@@ -906,11 +910,11 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
 
 	if (std_out != NULL)
 	{
-		hStdoutTempFile = GetTempFileHandle(error);
-		if (hStdoutTempFile == INVALID_HANDLE_VALUE)
+		gw_spawn.hStdoutTempFile = GetTempFileHandle(error);
+		if (gw_spawn.hStdoutTempFile == INVALID_HANDLE_VALUE || gw_spawn.hStdoutTempFile == NULL)
 		{
 			gchar *msg = g_win32_error_message(GetLastError());
-			geany_debug("win32_spawn: Second CreateFile failed (%d)", (gint) GetLastError());
+			geany_debug("win32_spawn: Stdout temp file creation failed (%d)", (gint) GetLastError());
 			if (error != NULL)
 				*error = g_error_new(G_SPAWN_ERROR, G_FILE_ERROR, "%s", msg);
 			g_free(msg);
@@ -988,8 +992,7 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
 	/* Read from pipe that is the standard output for child process. */
 	if (std_out != NULL)
 	{
-		ReadFromPipe(gw_spawn.hChildStdoutRd, gw_spawn.hChildStdoutWr, hStdoutTempFile, error);
-		if (! GetContentFromHandle(hStdoutTempFile, &stdout_content, error))
+		if (! GetContentFromHandle(gw_spawn.hStdoutTempFile, &stdout_content, error))
 		{
 			return FALSE;
 		}
@@ -998,8 +1001,7 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
 
 	if (std_err != NULL)
 	{
-		ReadFromPipe(gw_spawn.hChildStderrRd, gw_spawn.hChildStderrWr, hStderrTempFile, error);
-		if (! GetContentFromHandle(hStderrTempFile, &stderr_content, error))
+		if (! GetContentFromHandle(gw_spawn.hStderrTempFile, &stderr_content, error))
 		{
 			return FALSE;
 		}
@@ -1107,7 +1109,7 @@ static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline
 		TRUE,          /* handles are inherited */
 		CREATE_NO_WINDOW,             /* creation flags */
 		NULL,          /* use parent's environment */
-		w_dir,           /* use parent's current directory */
+		w_dir,           /* use specified directory */
 		&siStartInfo,  /* STARTUPINFO pointer */
 		&piProcInfo);  /* receives PROCESS_INFORMATION */
 
@@ -1124,14 +1126,29 @@ static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline
 	}
 	else
 	{
-		gint i;
-		DWORD dwStatus;
+		gboolean done = FALSE;
+		gint timeout_count = 0;
+		DWORD dwStatus, dwReadStdErr, dwReadStdOut;
+		do {
+			dwReadStdOut = ReadFromPipe(gw_spawn->hChildStdoutRd, gw_spawn->hChildStdoutWr, gw_spawn->hStdoutTempFile, error);
+			dwReadStdErr = ReadFromPipe(gw_spawn->hChildStderrRd, gw_spawn->hChildStderrWr, gw_spawn->hStderrTempFile, error);
+
+			dwStatus = WaitForSingleObject(piProcInfo.hProcess, 1*1000);
+			if (dwStatus == WAIT_TIMEOUT) {
+				if (dwReadStdOut > 0 || dwReadStdErr > 0)
+					timeout_count = 0;
+				else
+					timeout_count++;
+			} else if (dwStatus == WAIT_OBJECT_0) {
+				done = TRUE; // Process has exited normally
+			}
 
-		for (i = 0; i < 2 && (dwStatus = WaitForSingleObject(piProcInfo.hProcess, 30*1000)) == WAIT_TIMEOUT; i++)
-		{
-			geany_debug("CreateChildProcess: CreateProcess failed");
-			TerminateProcess(piProcInfo.hProcess, WAIT_TIMEOUT); /* NOTE: This will not kill grandkids. */
-		}
+			if (timeout_count >= 30) {
+				geany_debug("CreateChildProcess: output timeout expired");
+				TerminateProcess(piProcInfo.hProcess, WAIT_TIMEOUT); /* NOTE: This will not kill grandkids. */
+				done = TRUE;
+			}
+		} while(!done);
 
 		if (GetExitCodeProcess(piProcInfo.hProcess, &gw_spawn->dwExitCode) != 0)
 		{
@@ -1143,16 +1160,17 @@ static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline
 		}
 		CloseHandle(piProcInfo.hProcess);
 		CloseHandle(piProcInfo.hThread);
-		return bFuncRetn;
+		return (bFuncRetn == TRUE);
 	}
 	return FALSE;
 }
 
 
-static VOID ReadFromPipe(HANDLE hRead, HANDLE hWrite, HANDLE hFile, GError **error)
+static DWORD ReadFromPipe(HANDLE hRead, HANDLE hWrite, HANDLE hFile, GError **error)
 {
-	DWORD dwRead, dwWritten;
+	DWORD dwTotalRead, dwRead, dwWritten;
 	CHAR chBuf[BUFSIZE];
+	BOOL bSuccess = FALSE;
 
 	/* Close the write end of the pipe before reading from the
 	   read end of the pipe. */
@@ -1163,18 +1181,24 @@ static VOID ReadFromPipe(HANDLE hRead, HANDLE hWrite, HANDLE hFile, GError **err
 		if (error != NULL)
 			*error = g_error_new(G_SPAWN_ERROR, G_FILE_ERROR_PIPE, "%s", msg);
 		g_free(msg);
-		return;
+		return 0;
 	}
 
-	/* Read output from the child process, and write to parent's STDOUT. */
+	dwTotalRead = 0;
+
+	/* Read output from the child process, and write to the temp file. */
 	for (;;)
 	{
-		if (! ReadFile(hRead, chBuf, BUFSIZE, &dwRead, NULL) || dwRead == 0)
+		bSuccess = ReadFile(hRead, chBuf, BUFSIZE, &dwRead, NULL);
+		dwTotalRead += dwRead;
+		if (!bSuccess  || dwRead == 0)
 			break;
 
 		if (! WriteFile(hFile, chBuf, dwRead, &dwWritten, NULL))
 			break;
 	}
+
+	return dwTotalRead;
 }
 
 
