On Tue, 2007-06-19 at 19:52 -0600, Ximsce wrote: > Pedro Alves wrote: > > You didn't NULL terminate the argument list: > > http://www.opengroup.org/onlinepubs/000095399/functions/exec.html > > > > "The argument argv is an array of character pointers to > > null-terminated strings. The application shall ensure that the last > > member of this array is a null pointer. These strings shall constitute > > the argument list available to the new process image. The value in > > argv[0] should point to a filename that is associated with the process > > being started by one of the exec functions."
Even though the comments about the argv argument are accurate, this may not be the right reference to quote from. I've been looking for reference material on MSDN. Here's one : http://msdn2.microsoft.com/en-us/library/431x4c1w(VS.80).aspx The reason I'm being picky on this is I suspect that behaviour for open files may be different as well. The MSDN doc states three things that catch my attention : - deprecated API - open files remain open but you must flush before exec - translation mode of open files may change But more importantly, I have my suspicions about your source. I think the MSDN docs say that exec doesn't return (unless something went wrong), but spawn can be used with a parameter to make it create a new process. See http://msdn2.microsoft.com/en-us/library/20y988d2(VS.80).aspx and look into what _P_WAIT means. I suspect that you really want to replace the execv call by a spawn call with this parameter. I've tweaked your source a bit. You'll see an execv call, and a spawnv call. Depending on which one you comment out, the application behaves differently. Also note the fflush statement before execv or spawn. With execv the original application is *replaced* by the second one, so the END: text is never printed, the "Execution Complete" dialog is never shown. With spawnv, both do happen. Danny -- Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <windows.h> #include <stdio.h> #include <process.h> #define ERROR_LOG_FILE "/storage card/devel/log.txt" #define LAME_EXECUTABLE "/storage card/devel/exec2.exe" int encode() { FILE *logFile = fopen(ERROR_LOG_FILE, "a+"); if (logFile == NULL) { MessageBoxW(0, L"Failed to open log.txt", L"Log File failure", 0); exit(1); } fprintf(logFile, "BEGIN: log file opened.\n"); FILE *lame = fopen(LAME_EXECUTABLE, "r"); if(lame == NULL) { fprintf(logFile, "Couldn't read %s\n", LAME_EXECUTABLE); exit(1); } fclose(lame); fprintf(logFile, "Successfully read lame executable.\n"); char *args[3]; args[0] = LAME_EXECUTABLE; args[1] = 0; fflush(logFile); // execv(LAME_EXECUTABLE, args); spawnv(_P_WAIT, LAME_EXECUTABLE, args); fprintf(logFile, "END: finished encoding all files.\n"); fclose(logFile); MessageBoxW(0, L"Execution completed successfully.", L"Execution Complete", 0); return 0; } int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { encode(); return 0; }
#include <windows.h> #include <stdio.h> #include <process.h> #define ERROR_LOG_FILE "/storage card/devel/log.txt" #define LAME_EXECUTABLE "/storage card/devel/exec2.exe" int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { MessageBoxW(0, L"Yow", L"Baby baby", 0); return 0; }
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Cegcc-devel mailing list Cegcc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cegcc-devel