[SOLVED] How do basic applications communicate with each other?

Started by
11 comments, last by deadimp 17 years, 9 months ago
I've been wanting to know this for quite a while now: How do IDE's, like Dev-C++, receive output from applications, like MinGW "mingw32-make.exe"? How do they parse it (progress bar in compiling, line number of error, source file, etc)? My guess: When the IDE calls the compiler, it records data from the application and uses that (but that seems improbable); An I/O stream is established that the IDE records and the compiler uses, etc; A common file is established (I doubt this one) Is this concept similar on all other platforms, or do they have another way? Also, if there is a method, could I get the code in C++? EDIT: Forgot to mention, if you didn't notice it by MinGW, the platform I'm in is Windows. EDIT: Finally got my own small example to work. Hurrah. What it boils down to - The applications communicate by pipelines, and this communication is established by a parent process invoking the child process, setting the child's standard input, output, and error streams. In Windows, the main functions for this are: CreatePipe, SetHandleInformation, CreateProcess, and file I/O. In Unix, those lucky [people] get to use "fork()", and "pipe()". I really don't know why I just wrote this. [Edited by - deadimp on July 6, 2006 4:46:15 PM]
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
generally its done by redirecting stdout and stdin. (atleast in *nix)
Sorry for the noobish-ness, but how do they do that?
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
try reading up on pipes,

basically you need to use the pipe function to create pipes

int pipe(int filedes[2]); will set filedes[0] and filedes[1] to the pipes read and write end respectivly. then you can use fcntl to duplicate stdin or stdout
oh and you might need the dup2 function aswell
I can't find "fork()" (or "pipe") in MinGW (well, in <unistd.h> and two other related headers), and I've seen it in the few exapmles I've looked at.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
hmm right, those are unix specific.

try looking at createprocess on msdn. (i would guess that dup2 and pipe are unix specific aswell then so you might need to get help from some windows dev)
BOOL WINAPI CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);


the lpStartupInfo struct

typedef struct _STARTUPINFO { DWORD cb; LPTSTR lpReserved; LPTSTR lpDesktop; LPTSTR lpTitle; DWORD dwX; DWORD dwY; DWORD dwXSize; DWORD dwYSize; DWORD dwXCountChars; DWORD dwYCountChars; DWORD dwFillAttribute; DWORD dwFlags; WORD wShowWindow; WORD cbReserved2; LPBYTE lpReserved2; HANDLE hStdInput; HANDLE hStdOutput; HANDLE hStdError;
} STARTUPINFO, *LPSTARTUPINFO;


has 3 handles at the end, one for stdin , one for stdout, and one for stderr, you can create an instance of that struct, set the hStdOutput handle to a handle created by your application and then read from it.

you need to set STARTF_USESTDHANDLES in dwFlags aswell.
Well, I also have VC++, looked in the help manual, and found "_pipe", with different arguments, "_dup2" (same arg's), but no "fork". I'll look into "CreateProcess", but I really like the simplicity of the Unix stuff.

EDIT: Well, I looked into it, but it doesn't seem the same, and I haven't exactly gotten into any depth on OS process, threads, etc.
I'll keep on searching for examples.

EDIT (again): Didn't see your previous post... And didn't see the std handles when looking (/skimming) the startup struct. Need to look further into handles... Can you directly convert an "int" file id to "HANDLE"? Or do you need to use Windows to create it?

NOTE: Argh! Connection keeps on resetting!
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Well, I found a Windows tutorial on this in the MSDN, just need to go through it a few times, write my own small wrapper, and I'll be good (this was just a question for curiosity).

Is there any simple way to convert Windows file handles to standard file handles?

EDIT: Oh yeah, here's the link

[Edited by - deadimp on July 6, 2006 3:32:13 PM]
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement