+ free( psz_cmd );
+ return -1;
+ }
+
+ i_size = 32768;
+ ppsz_parser = &ppsz_env[0];
+ while ( *ppsz_parser != NULL && i_size > 0 )
+ {
+ memcpy( p, *ppsz_parser,
+ __MIN((int)(strlen(*ppsz_parser) + 1), i_size) );
+ p += strlen(*ppsz_parser) + 1;
+ i_size -= strlen(*ppsz_parser) + 1;
+ ppsz_parser++;
+ }
+ *p = '\0';
+
+ /* Create the child process. */
+ bFuncRetn = CreateProcess( NULL,
+ psz_cmd, // command line
+ NULL, // process security attributes
+ NULL, // primary thread security attributes
+ TRUE, // handles are inherited
+ 0, // creation flags
+ p_env,
+ psz_cwd,
+ &siStartInfo, // STARTUPINFO pointer
+ &piProcInfo ); // receives PROCESS_INFORMATION
+
+ free( psz_cmd );
+ free( p_env );
+
+ if ( bFuncRetn == 0 )
+ {
+ msg_Err( p_object, "child creation failed" );
+ return -1;
+ }
+
+ /* Read from a file and write its contents to a pipe. */
+ while ( i_in > 0 && !p_object->b_die )
+ {
+ DWORD i_written;
+ if ( !WriteFile( hChildStdinWr, p_in, i_in, &i_written, NULL ) )
+ break;
+ i_in -= i_written;
+ p_in += i_written;
+ }
+
+ /* Close the pipe handle so the child process stops reading. */
+ CloseHandle(hChildStdinWr);
+
+ /* Close the write end of the pipe before reading from the
+ * read end of the pipe. */
+ CloseHandle(hChildStdoutWr);
+
+ /* Read output from the child process. */
+ *pi_data = 0;
+ if( *pp_data )
+ free( pp_data );
+ *pp_data = NULL;
+ *pp_data = malloc( 1025 ); /* +1 for \0 */
+
+ while ( !p_object->b_die )
+ {
+ DWORD i_read;
+ if ( !ReadFile( hChildStdoutRd, &(*pp_data)[*pi_data], 1024, &i_read,
+ NULL )
+ || i_read == 0 )
+ break;
+ *pi_data += i_read;
+ *pp_data = realloc( *pp_data, *pi_data + 1025 );