News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

writing back to a pipe

Started by Slugsnack, July 26, 2009, 11:33:30 AM

Previous topic - Next topic

Slugsnack

heya

so i've been able to successfully redirected the input FROM a console application to my GUI app for a while now. but now what I want to do is make it so i can also direct text from my GUI app TO the console app.

to pipe from the console application i simply set hStdOuput/hStdError to the write end of my pipe and then polled for contents in the console with readfile and checking the number of bytes read. i am under the impression that there can only be one end of a pipe existing which means i should be piping my text back through the same write end of the pipe ? however this is not really working.. not sure why. i am checking that the pipe is empty before writing to it but whatever i do doesn't seem to work

Tedd

Yeah, that won't work :P

Pipes are one-way only. Unless you make a named-pipe, and then you can make it two-way, but both ends have to be expecting it -- the console doesn't.
But, you're in luck :wink You make yet another pipe and attach it to STD_INPUT_HANDLE in the same way, but (I think) you get the write end and give the console the read end; then WriteFile to it - the console will get whatever you write when it tries to read from stdin (i.e. reading user input.)
No snowflake in an avalanche feels responsible.

Slugsnack

my current attempt.. any ideas ?

[attachment deleted by admin]

Tedd

Have a working example :P


[attachment deleted by admin]
No snowflake in an avalanche feels responsible.

Slugsnack

Tedd : thanks ! at work right now but i will definitely check that out once i get home  :U

Slugsnack

Tedd : your app doesn't do anything when i run it on my machine. i amended my code but it's being really weird now.. it's like the pipes are connected to each other but no longer to cmd.exe. in fact the process doesn't even show lol. however if i send stuff then it's read and displayed via the pipe..

and now the program hands again when i'm trying to close it  :(



[attachment deleted by admin]

Slugsnack

modified some more to get the read pipe working again. i'm using a different pipe for read/write. the write one at least seems to write.. SOMETHING onto the pipe but i get something really weird.. "more?" ?!?!



attached updated code

btw that 'more' appeared after i had used my edit control to pipe 'ping /?' to the console. underneath another real console shows what i was expecting it to output..

[attachment deleted by admin]

Slugsnack

ha simple.. needed to change the WriteFile number of bytes to write from 1024 to eax ( return of GetDlgItemText )

ends up writing 1024 - string length NULLs before the CRLF : P ( well before it did )