Jump to content
  • Advertisement
Sign in to follow this  
deadimp

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

This topic is 4422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
generally its done by redirecting stdout and stdin. (atleast in *nix)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oh and you might need the dup2 function aswell

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!