supportoranges
asked on
Spawing a process from debugger by stepping through a system call fails. (MSVS 2010, C++, R)
I have been unable to use system() or Winexec() or CreateProcess to spawn a process to run another executable. Granted the other executable was C++ with an RInside component instantiated within and compiled with gcc (of Rtools fame).
These same techniques had no trouble launching notepad.exe.
I am expecting my program to launch a fresh process and wanted to step through the parent process (the spawner) in debug, but whenever I did that, all I get is DOS virtual VM 'blinking'. Only when I ran my executable outside of the debugger did the program run to completion.
Granted, I could run a .bat very easily and in ran without a hitch, but the nested .exe within the .bat only blinked a DOS VM and didn't run the pgm.
I cannot understand why hitting STEP would spawn a new process or make a system call in a different way inside the debugger. If a process is spawned, why would it matter if it was spawned as a result of stepping through code.
These same techniques had no trouble launching notepad.exe.
I am expecting my program to launch a fresh process and wanted to step through the parent process (the spawner) in debug, but whenever I did that, all I get is DOS virtual VM 'blinking'. Only when I ran my executable outside of the debugger did the program run to completion.
Granted, I could run a .bat very easily and in ran without a hitch, but the nested .exe within the .bat only blinked a DOS VM and didn't run the pgm.
I cannot understand why hitting STEP would spawn a new process or make a system call in a different way inside the debugger. If a process is spawned, why would it matter if it was spawned as a result of stepping through code.
ASKER
Thank you for the response and the code.
I went back to
system(path);
just to keep it very simple.
The behavior is the same. CString path is fully qualified path and looks great in the debugger. It is so correct I can even copy and paste from text visualizer value in the debugger directly to W7 "run" button and it runs.
Furthermore, a previous call to system(path) calling a script works fine.
The only thing I can think of is that in the problem case, maybe the debugger's PATH is overriding the normal ENV vars. The program I am trying to run is a C++/RInside executable which must load some R DLLs.
I went back to
system(path);
just to keep it very simple.
The behavior is the same. CString path is fully qualified path and looks great in the debugger. It is so correct I can even copy and paste from text visualizer value in the debugger directly to W7 "run" button and it runs.
Furthermore, a previous call to system(path) calling a script works fine.
The only thing I can think of is that in the problem case, maybe the debugger's PATH is overriding the normal ENV vars. The program I am trying to run is a C++/RInside executable which must load some R DLLs.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok i will go back to CreateProcess and report back. thank you.
ASKER
Thank you for your help. Problem continues.
I have supplied the calling code (below) and the called code (attached).
You see I am just trying to run my.exe . Running notepad.exe thru step through is no problem as the comments indicate..
//START OF CALLER
path="C:\\projects\\ICS\\m y.exe ";
//-- TRY THIS INSTEAD
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRes;
DWORD dwCode = 0;
MSG msg;
ZeroMemory( &si, sizeof ( STARTUPINFO) );
si.cb=sizeof( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
//this simply blinks a DOS VM
bRes = CreateProcess ( NULL, "C:\\projects\\ICS\\my.exe ", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);
bRes = CreateProcess ( NULL, "notepad.exe ", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
//runs ok
//this is suspicious
//system(path);
system("notepad"); //but this runs ok
//attached.
Called code (simple.cpp) that gets compiled in the special way RInside for Windows insists on. This is simplified from original my.cpp. simple.cpp has no problem running once compiled. it runs from RUN menu or DOS-VM but from IDE debug it only flashes.
simple.cpp
I have supplied the calling code (below) and the called code (attached).
You see I am just trying to run my.exe . Running notepad.exe thru step through is no problem as the comments indicate..
//START OF CALLER
path="C:\\projects\\ICS\\m
//-- TRY THIS INSTEAD
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRes;
DWORD dwCode = 0;
MSG msg;
ZeroMemory( &si, sizeof ( STARTUPINFO) );
si.cb=sizeof( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
//this simply blinks a DOS VM
bRes = CreateProcess ( NULL, "C:\\projects\\ICS\\my.exe
CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);
bRes = CreateProcess ( NULL, "notepad.exe ", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
//runs ok
//this is suspicious
//system(path);
system("notepad"); //but this runs ok
//attached.
Called code (simple.cpp) that gets compiled in the special way RInside for Windows insists on. This is simplified from original my.cpp. simple.cpp has no problem running once compiled. it runs from RUN menu or DOS-VM but from IDE debug it only flashes.
simple.cpp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for thoughtful reply. I will try your suggestions and give the result within 48hrs. All the best.
ASKER
I think these are good recommendations, and while I will not have time to try everything out, I want to thank both of you for your thoughtful responses.
I didn't feel it was fair to delete the question, but I feel there is something going on in the R environment that is thwarting my efforts to execute the dynamic link.
Unfortunately, I cannot see having time to go through all the recommendations within the next few weeks and so I wanted to close it out with thanks to all.
I didn't feel it was fair to delete the question, but I feel there is something going on in the R environment that is thwarting my efforts to execute the dynamic link.
Unfortunately, I cannot see having time to go through all the recommendations within the next few weeks and so I wanted to close it out with thanks to all.
Open in new window