From: 1gor Date: 2006-07-10T01:50:05+09:00 Subject: Ruby C extension/wrapper around C function that uses scanf and printf I need Ruby to access a set of external command line applications for dataseries analysis. Each of these little apps simply reads data from stdin and then outputs processed results to stdout (using scanf and printf, they are all written in C). These functions have to be accessed repeatedly when iterating over large chunks of data, so accessing them through the pipe (popen or popen3) doesn't work. Launching/closing an external process 3000 times in a row results in errors. And that's not efficient. So I have to write extension for each of those little C programs, a wrapper of sorts. I have learned how to write and compile an extension for Ruby. I can import an extension, pass an array of data to it and return some data from the extension. The problem is that I have no C experience and dread thinking of having to replace each 'scanf' routine with my custom array of imported data (memory allocation, writing iterator etc.). Each input function here starts with: while (scanf("%lf", &y) == 1) { ... etc. and then follows to process input data, handle cases with input buffer is too large etc. I would very much like to leave these input() functions as they are and just feed them my data from Ruby code. Is it possible to fill stdin buffer with data from Ruby code and then simply call existing C function that uses 'scanf'? I couldn't simply assign an array to $stdin variable in Ruby, gave TypeError (File expected)...