c++ - Linux passing continuous output as command line args -



c++ - Linux passing continuous output as command line args -

i have machine vision programme (./detectupdatehomeml) continuously outputs name of objects found terminal using next code:

circle( img, center, radius, color, 3, 8, 0 ); if (circle) { std::cout << " " << cascadename << " " << timefound() << endl; std::cout << std::flush; } int timefound() { time_t rawtime; struct tm * timeinfo; char buffer [80]; time (&rawtime); timeinfo = localtime (&rawtime); strftime (buffer,80," %y-%m-%dt%h:%m:%s",timeinfo); std:cout << (buffer); eventcount++; }

i looking send input command line arguments sec programme using back-ticks capture output , send other programme so:

./acceptinput `./detectupdatehomeml`

however arguments don't seem getting passed ./acceptinput.

i have test programme called ./testinput prints hello world! so:

std::cout << "hello world!";

when using same command:

./acceptinput `./testinput`

the programme works , outputs expected:

there 3 arguments: 0 ./acceptinput 1 hello 2 world!

what going wrong when seek pass continuous output ./detectupdatehomeml ./acceptinput program?

it looks detectupdatehomeml produces events want handle acceptinput. in case, have slight mismatch in info flow can resolve xargs, so:

./detectupdatehomeml | xargs -n2 ./acceptinput

when executing programme arguments, parent process (for illustration bash) needs know how many arguments there before starting execution, when do

./acceptinput `./detectupdatehomeml`

bash must wait until detectupdatehomeml has finished running before starting acceptinput.

in order utilize output detectupdatehomeml while still running, utilize pipes:

./detectupdatehomeml | ...

this redirect output detectupdatehomeml standard input of program.

xargs accepts space-separated text in input , executes subprocesses giving text arguments. utilize -n decide how many arguments passed each time, illustration 2:

./detectupdatehomeml | xargs -n2 ...

xargs takes name of subprocess execute:

./detectupdatehomeml | xargs -n2 ./acceptinput

now, every time detectupdatehomeml generates 2 items of output, acceptinput executed these 2 arguments.

this allow run detectupdatehomeml continuously while acceptinput executed every time detectupdatehomeml has generated sufficient output. should solve problem.

c++ linux shell command-line-arguments

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -