Hi again,
sorry, but my problem isn't solved.
First Example (see above) was running well.
But because it wasn't that what I want, I do some other tests
and the result was always the same. Program chrashed at end of execution.
If you test the code an uncomment "#define TEST" the prog crashed
example code:
// *************************************************************************
//#define TEST
// *************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
// *************************************************************************
FILE *log=NULL;
// ***************************** Code Start *********************************
int TestSpawn(const char *ufile)
{
long long notepad_id=0;
int rc=0;
notepad_id=_cwait (&rc, _spawnl(_P_NOWAIT, "C:\\Windows\\notepad.exe\0", "notepad.exe\0", ufile, 0), 0);
fprintf(log, "\n STATUS %d, NPAD_ID %lld\n", rc, notepad_id);
return rc;
}
// *************************************************************************
int main(int argc, char **argv)
{
FILE *test=NULL;
int rc=0;
const char *log_file="D:\\Temp\\T\\T.log\0", *user_file="D:\\Temp\\T\\T1.txt\0", *test_file="D:\\Temp\\T\\T2.txt\0";
log=fopen(log_file, "w+");
if(!log)
{
perror("\n No Log File ");
exit(EXIT_FAILURE);
}
fprintf(log, "\n Log File is open\n");
rc=TestSpawn(user_file);
#ifdef TEST
test=fopen(test_file, "w");
if(!test)
{
perror("\n No Test File ");
exit(EXIT_FAILURE);
}
if(test) fprintf(test, "\n Test File is open");
fprintf(test, "\n STATUS %d\n", rc);
fprintf(test, "\n Test File closed\n\n END\n");
fflush(test);
fclose(test);
#endif
fprintf(log, "\n STATUS %d\n", rc);
fprintf(log, "\n Log File closed\n\n END\n");
fflush(log);
fclose(log);
fprintf(stdout, "\n END STATUS %d\n", rc);
fprintf(stdout, " END\n");
return EXIT_SUCCESS;
}
// **************************** Code End *****************************
compiler flags: -std:C11 -Tx64-coff -Zi -Ob0 -fp:precise -W1 -Gr -J
linker flags: -subsystem:console -machine:x64 -LIBPATH:C:\PellesC\Lib\Win64 kernel32.lib user32.lib advapi32.lib delayimp64.lib
error message:
CRT: unhandled exception (main) -- terminating
*** Process returned 255 ***
Press any key to continue...
debug: Access violation --->>> fclose(file)
Tested with 3 PCs
Win7- intel i3, Win8.1- intel i5, Win10-intel i7
If this is not the right sub-forum, feel free to move it.
regards and thanks
Jens