Título: quien me ayuda con este codigo Publicado por: _alexis_ en 28 Abril 2010, 23:54 pm #include <windows.h>
#include <stdio.h> #define BUFSIZE 4096 HANDLE hChildStdoutRd, hChildStdoutWr, hStdout; BOOL CreateChildProcess (char *cmdline) { PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; BOOL bFuncRetn = FALSE; // Set up members of the PROCESS_INFORMATION structure. ZeroMemory (&piProcInfo, sizeof (PROCESS_INFORMATION)); // Set up members of the STARTUPINFO structure. ZeroMemory (&siStartInfo, sizeof (STARTUPINFO)); siStartInfo.cb = sizeof (STARTUPINFO); siStartInfo.hStdError = hChildStdoutWr; siStartInfo.hStdOutput = hChildStdoutWr; siStartInfo.dwFlags |= STARTF_USESTDHANDLES; // Create the child process. bFuncRetn = CreateProcess (NULL, cmdline="notepad.exe", NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo); if (bFuncRetn == 0) { printf ("CreateProcess failed\n"); return FALSE; } else { CloseHandle (piProcInfo.hProcess); CloseHandle (piProcInfo.hThread); return bFuncRetn; } } int ReadFromPipe () { DWORD dwRead, dwWritten; char chBuf[BUFSIZE]; // Close the write end of the pipe before reading from the // read end of the pipe. if (!CloseHandle (hChildStdoutWr)) { printf ("Closing handle failed"); return -1; } // Read output from the child process, and write to parent's STDOUT. for (;;) { if (! ReadFile (hChildStdoutRd, chBuf, BUFSIZE, &dwRead, NULL) || dwRead == 0) { break; } if (! WriteFile (hStdout, chBuf, dwRead, &dwWritten, NULL)) break; } return 0; } int main (int argc, char *argv[]) { SECURITY_ATTRIBUTES saAttr; BOOL fSuccess; // Get a handle to the parent's input file. if (argc == 1) { printf ("Must be a parameter.\n"); return -1; } // Set the bInheritHandle flag so pipe handles are inherited. saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; // Get the handle to the current STDOUT. hStdout = GetStdHandle (STD_OUTPUT_HANDLE); // Create a pipe for the child process's STDOUT. if (! CreatePipe (&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) return -2; // Ensure that the read handle to the child process's pipe for // STDOUT is not inherited. SetHandleInformation (hChildStdoutRd, HANDLE_FLAG_INHERIT, 0); // Now create the child process. fSuccess = CreateChildProcess (argv[1]); if (! fSuccess) return -3; printf ("\nContents of %s:\n\n", argv[1]); // Read from pipe that is the standard output for child process. ReadFromPipe (); return 0; } lo q necesito es darle paramatros al programa pero no caxo como ??? Título: Re: quien me ayuda con este codigo Publicado por: Gallu en 29 Abril 2010, 00:28 am Para recibir parametros en el programa utilizas los que recibe el main
Código
de echo aquí lo estás usando , deduzco que te has copiado este código de algún sitio Código
Título: Re: quien me ayuda con este codigo Publicado por: _alexis_ en 29 Abril 2010, 01:32 am si pero no le pasa ningun parametro
Título: Re: quien me ayuda con este codigo Publicado por: Gallu en 29 Abril 2010, 09:01 am si pero no le pasa ningun parametro Explicate mejor , te he dicho como recibir los parámetros en el programa , para pasarselos lo haces escribiendo nombre_programa.exe param1 param2 , etc.... |