CreateProcess problem.
-
-
A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax
-
A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax
Can you show how to use._**
**_
whitesky
-
how do u try to open the file? Try opening the the file using the full path not relative. I doubt the problem happens because of the change in the working directory of the b.exe. nave
-
Can you show how to use._**
**_
whitesky
Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax
-
Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax
iLoveM wrote:
FILE *f = fopen(read,"rb");
u try opening the file in write mode. if that too failes, u can conclude one of the following 1. A file already exist in that path and is been opened by another process 2. Path is invalid 3. Don't have privilage and let me know the results nave
-
A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax
iLoveM wrote:
Why?
You should be telling us why. :confused: If you are opening the file via
CreateFile()
and it's failing, what doesGetLastError()
return?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax
iLoveM wrote:
FILE *f = fopen(read,"rb");
If
fopen()
fails, what is the value oferrno
?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax
It's too strange!!! STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; CHAR szFolderWhereFileIsLocated[250]={0}; strcpy(szFolderWhereFileIsLocated ,"put path here"); PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, szFolderWhereFileIsLocated, &si, π); when i put these code in a console program, the sub process can open correctly. Then in my windows program, the sub process can't open file firstly, then start up the sub process again (my program will start up the sub process every 20 sec) , it's OK. Just relax