For timing out a spawned child see alarm and the working example in there.
For reading back the output of the child, why not make child write its output to a specified file, via a command line parameter, e.g. `child.exe -o out.123`, or `child.exe > out.123`. 123 could be child's pid. Problem with incomplete output if you timeout child, so add a marker at EOF indicating successful completion of process.
But you need to keep track of how many children are currently running because you don't want to overwhelm your system. And that additional requirement leads us to a thread-pool where children splash. This example by BrowserUK is a classic in my books: How to create thread pool of ithreads
1min addition: Sharing data between threads is possible but somewhat tedious, you want to keep it to a minimum (I don't like data duplicating), e.g. notifying of children pids. It is possible and easy to communicated via shared variables, integers, strings etc. but moving to shared deep data structures or objects is something you don't want because even if it is possible (I don't know) you can do without the overhead.
bw, bliako
In reply to Re: non-blocking backticks
by bliako
in thread non-blocking backticks
by chris212
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |