I am looking for a way to process data using some small command-line utilities that each do 1 thing. (I run under windows).
I have a variable, @data, containing, well data ;)
I want to pass it to the first program, read the results. Then I want to pass the results to the second program and read the final answer. (it would be ideal to get to munge the @data between calling prog1 and prog2)
Kinda like: @ans = `getnames | sort`
But, I want to pass @data to getnames (which will do some work) and then have the results goto sort (which will do more work), then back in my Perl program.
One option might be to use 1 or more temporary files:
write @data to temp1.dat
execute `type temp1.dat | getnames > temp2.dat`
(would be ideal to muncge @data here...)
execute `type temp2.dat | sort > temp3.dat`
@ans = `type temp3.dat`
I had originally thought stdin and maybe Open2 would work, but, 'kwoff' pointed out that Open2, will block for programs like "sort".
I do have access to the "c" source of the utilites. So I could go in and make sure that I read all stdin and close it before I try to write to stdout. (I think it does this already...from what I can tell ;-)
One cool thing about Unix is all of those small utilities that you can combine into powerfull functions...I hope to emulate this, instead of using temp files that need to be cleaned up...
This might be hard or easy, but please don't assume, I know what I am doing ;-) and thanks for any ideas
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.