Ok, its been a while since I have posted a Newbie style question so I thought that I would take the time and do so now  8)

For my H8 firmware development I am using and IDE that when the build all option is selected shells out and makes calls to external assemblers and linkers (which are DOS based applications).  What I would like to know, and thusly the reason of my post, what is the proper way to have one application (such as a development IDE) shell out to these DOS based executables and capture (then redirect to a Windows based console show within your IDE) the output of these files?

The reason that I am asking is because I am currently developing a set of programs that automate the process of building our various firmwares and rom images.  The only portion that I have not done yet is the IDE replacement (as mentioned above) so any help from anyone who has already developed IDE's and dealt with this issue (or done other such work) would be greatly appreciated.

Thanks.

Posted on 2007-11-09 20:31:09 by madprgmr
mybat.bat:
@echo off
IF "%1"=="" GOTO end
GOTO start
:loop
SHIFT
:start
myapp1 < %1 > outputfile.txt
IF NOT "%2"=="" GOTO loop
:end


or something like that.
Posted on 2007-11-09 20:40:21 by ti_mo_n
Thanks for the batch file; however, while that would work what I am really looking for is the way that developmental IDE's (i.e. RadAsm) perform the action.

Posted on 2007-11-09 20:50:21 by madprgmr
DOS programs or win32 console applications? Please make the distinction :)

What you want to do, anyway, is CreateProcess with startupinfo.hStd{Output,Error} set to pipes (and those pipes created with securitattr.inherithandle=true).
Posted on 2007-11-10 04:58:48 by f0dder

DOS programs or win32 console applications? Please make the distinction :)


Ah...stupid me (must be the first signs of old age :) ) I never even thought of it that way until you pointed it out to me (duh.... of course I meant win32 console application).  On the positive side, I did say that this was going to be a newbie type post and what better way then to make the classic newbie mistake  :P


What you want to do, anyway, is CreateProcess with startupinfo.hStd{Output,Error} set to pipes (and those pipes created with securitattr.inherithandle=true).


Great...Thanks for the info (and the slap on the wrists with the wooden ruler  :D ) as this is exactly what I needed.

Well...time to go take care of all the animals. Have a great weekend.

Posted on 2007-11-10 11:03:34 by madprgmr
Note one big huge shortcoming of pipes: you cannot WaitFor*Object on them. If you ever want to do that, the closest would be spawning a thread that does blocking read, and fires an event once a read goes through... pretty messy, I can't understand why MS didn't make it possible to WaitFor*Object on pipes :(
Posted on 2007-11-10 11:11:29 by f0dder
you can take there wafasm source, which have CreatePipeAndExecuteCon function (originally written by Antonis Kyprianou, then modified by me), which redirects output using intermediate console application (also source in fasm present)

the matter is it is impossible redirect output of DOS application to GUI application as GUI has no own console while DOS app. (unlike win32 console) needs explicite console creation, so, win32 console conspawn application used for this.
Posted on 2007-11-21 05:09:56 by Shoo

the matter is it is impossible redirect output of DOS application to GUI application as GUI has no own console while DOS app. (unlike win32 console) needs explicite console creation, so, win32 console conspawn application used for this.

Hmmm?

Are you saying you can't redirect stdin/stdout handles of child process just because you don't have a console created? Nah :)

Second, if you want to output to a console and not just capture text, a GUI process can still call AllocConsole(), after which you can use GetStdHandle() to get the input/output handles.

But perhaps I misunderstood you?
Posted on 2007-11-21 06:47:03 by f0dder
from gui application you can redirect output for child win32 console application. with dos application you will get an error - broken pipe.

but it is possible to redirect output of dos applications, when they started from win32 console application. thus i do use with add-in intermediate hidden conspawn application - it similar to ms conspawn from msdn, just redirects also errorlevel additionally.

i have tried different ways, but failed to create pipe directly to dos application from windows gui application.
-----------------
a GUI process can still call AllocConsole(),

yes, and after this immediatelly appears black console window - who will like it, even if you will quickly hide it?


Posted on 2007-11-21 07:15:30 by Shoo
Aaaah, DOS applications specifically - I thought you just meant "console app", like most people who write "DOS app". Sorry for that! :)

As for allocating console for GUI app - you should only do it if you need it (and you don't need it just to redirect child app handles).
Posted on 2007-11-21 08:29:49 by f0dder