c++ - How to WriteConsoleInput to the a child app waiting at ReadConsoleInput? -


so have been attempting read , write pianobar (console pandora player) stdin , stdout control within application.

however, when reading stdout blocks @ last line (where displays time of song).

i thought doing wrong (probably still am) downloaded demo project sending/receiving input applications stdin/stdout via couple handles.

so dove pianobar code, , put in printf commands on place trace block occurring (is block right word this?) anyways section of code appears loop extremely when created child process, , blocks stdout.

from pianobar, ui_readline.c barreadline replacement

/*  readline replacement  *  @param buffer  *  @param buffer size  *  @param accept these characters  *  @param input fds  *  @param flags  *  @param timeout (seconds) or -1 (no timeout)  *  @return number of bytes read stdin  */ size_t barreadline (char *buf, const size_t bufsize, const char *mask,         barreadlinefds_t *input, const barreadlineflags_t flags, int timeout) { // took out code here ... printf("in barreadline 005\n"); fflush(stdout); while (true) {     sleep(400); // added stop doing 100% on core     printf("in barreadline 006\n");     fflush(stdout);     if (timeout != infinite) {         dword = gettickcount ();         printf("in barreadline 007\n");         fflush(stdout);         if ((int)(now - timestamp) < timeout) {             timeout -= (int)(now - timestamp);             timestamp = now;         }         else             timeout = 150; // kyle changed 0     }     printf("current timeout: %d\n",timeout);     printf("in barreadline 008\n");     fflush(stdout);     waitresult = waitforsingleobject (handle, timeout);      printf("in barreadline 009\n");     fflush(stdout);     if (wait_object_0 == waitresult) {         input_record inputrecords[8];         input_record* record;         dword recordsread, i;          printf("in barreadline 010\n");         fflush(stdout);         successconsole = readconsoleinput (handle, inputrecords, sizeof(inputrecords) / sizeof(*inputrecords), &recordsread);         if(successconsole != 0) {             printf("we read console\n");         }          printf("in barreadline 011\n");         fflush(stdout);         (i = 0, record = inputrecords; < recordsread; ++i, ++record) {             int codepoint, keycode;              printf("in barreadline 012\n");             fflush(stdout); 

and code above prints out:

in barreadline 005 in barreadline 006 in barreadline 007 current timeout: 150 in barreadline 008 in barreadline 009 in barreadline 010 in barreadline 011 in barreadline 006 in barreadline 007 current timeout: 150 in barreadline 008 in barreadline 009 in barreadline 010 in barreadline 011  

anyways, can bash "input" key on redirect demo app known key doesn't require special , keeps spinning through loop , doesn't seem catch it, me sounds 1 of 2 things; don't have access input function being blocked reading of stdout, or readconsoleinput isn't recognizing things send redirect demo.

is need send type of async i/o process? , why using "cmd" , opening regular command prompt not cause blocking, does?

update 1: managed build input_record send readconsoleinput within pianobar (child console). however, i'm finding parent application returning "invalid handle" when try send writeconsoleinput(m_hstdinwrite, inputrecords, sizeof(inputrecords) / sizeof(*inputrecords), &dwwritten);

are there different types of handles child's console stdin? using writefile works, cannot send input_records way.

redirect demo app

pianobar windows binaries

pianobar windows build environment

helped, not sure what's causing invalid handle: low level console input , redirection

i believe because program using readconsoleinput instead of readfile. readconsoleinput requires console handle.

you need create console , pass handle. you'd need write console input events it.

it'd better if change other program use readfile, if make work.

this seems msdn reference consoles.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -