NO

Author Topic: Sending messages back from CreateProcess  (Read 3666 times)

tpekar

  • Guest
Sending messages back from CreateProcess
« on: August 19, 2011, 06:49:47 PM »
In PowerC I used the system() command to execute a child process.  Had the child process write to the console screen.  Then used the peek command in the parent to "screen scrape" the message from the child.  I use CreateProcess in Windows to call the child process and am looking for an easy way for the child to communicate back to parent (send a message back).

CommonTater

  • Guest
Re: Sending messages back from CreateProcess
« Reply #1 on: August 19, 2011, 07:47:38 PM »
What kind of message?

If you can use a 32 bit unsigned int to represent the message you can use the return value of the process...

Child...
Code: [Select]
int main (void)
 {  // do a buch of stuff

    return MsgVal; }
Parent...
Code: [Select]
DWORD MsgValue;
// a mess of code...
// launch child with CreateProcess()
GetExitCodeProcess(hProcess,&MsgValue);

There are other methods as well... for example you can use inter-process messaging such as PostThreadMessage() and WM_COPYDATA to send a message from child to parent, provided the childe knows the parent's thread handle which you can also send inter-process to the child...  Another option is memory mapped files and semiphore files (child writes file to disk before exiting, parent reads the file after the child returns)...

It really depends on what you are passing back and forth and how big the messages are...




Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Sending messages back from CreateProcess
« Reply #2 on: August 19, 2011, 09:04:56 PM »
Try the example called Creating a Child Process with Redirected Input and Output.

Another way is to use the _popen function, which can be found in the help file under Standard C99 #include files => stdio.h, which allows to establish a pipe using the system() function.
Make sure to read the whole paragraph, especially the remarks.
---
Stefan

Proud member of the UltraDefrag Development Team