Hi,

At the moment I am trying to open a log file with notepad.exe while the original process continues. As I am developing for Windows, fork() is not available for me. I googled alot and found a good reference to opening processes (http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html), however they all put the original process into a hold. For example:

exec("notepad.exe", "logs/Log.log", 0);

or

system("notepad.exe logs/Log.log");

All stop the original process. Does anyone know the way to fix my problem? I am developing on Windows XP and am using Code::Blocks as IDE.

Thanks in advance,
~G

You want to call CreateProcess() The function isn't nearly as bad as it looks because some of the parameters can be 0 For example

STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
memset(&sinfo,0,sizeof(STARTUPINFO));
sinfo.cb = sizeof(STARTUPINFO);
memset(&pinfo,0,sizeof(PROCESS_INFORMATION);

CreateProcess("Notepad.exe","c:\\logs\\Log.log",0,0,FALSE,0,0,0,&sinfo,&pinfo);

Edited 5 Years Ago by Ancient Dragon: n/a

Comments
Thank you, that did it!

Thanks for the help, that solved my problem!

PS: Also, you forgot to close the memset() function in line 5 with a ) on the end, might want to adjust that ;)

One other small adjustment: a space is required at the beginning of the second parameter in order to work, this is because it is directly parsed behind the process name. Also, it does not automatically search the system folders for a known process, such as notepad.exe . I added a copy of notepad.exe instead of finding the location of it on the system the process is being run (which is also a good possiblity). The full code that works good:

STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
memset(&sinfo,0,sizeof(STARTUPINFO));
sinfo.cb = sizeof(STARTUPINFO);
memset(&pinfo,0,sizeof(PROCESS_INFORMATION));
CreateProcess("notepad.exe", " logs\\log.log", 0, 0, FALSE, 0, 0, 0, &sinfo, &pinfo);

~G

This question has already been answered. Start a new discussion instead.