Abigail-II has provided an execellent answer (node 304670) to a similar problem in the answer to "passing string to stdin on exec-command". I think this is probably what you are looking for.
| [reply] |
In my job, I am often in a position where I have to repeat a process on a long list of files, and the process is such that I can only do one file at a time -- e.g. each run produces an output file whose name is derived somehow from the input file name, or whatever.
So one of the first things I did after getting started with perl several years ago was to create a general purpose script that I called "shloop" (as in "shell loop", or more exactly, "sh loop", because it's really just an easier, more flexible tool to use in place of the "for x in ..." loop in (ba)sh). I posted it here.
If there's a process called "mktrace" which only accepts one file name, and I have a long list of file names, I could do:
shloop -e mktrace filename.list
Or if the list were all files in the current directory whose names end in ".fasta" or somesuch, I could do:
ls *.fasta | shloop -e mktrace
On unix, it starts by opening a shell with:
open( SH, "| /bin/sh" ) or die "Couldn't start sub-shell";
Then on each iteration of the loop (as it reads lines from STDIN or a list file), it assembles a "$commandline" by putting the list element together with the value of the "-e" option, and then just does:
print SH $commandline;
The pod provided with the script is pretty extensive (there are a lot more options, like using regex substitutions to create a proper output file spec from the input, putting input and output strings at various points in the command string, etc). If it doesn't suit your needs, it might at least provide some ideas for things to try. | [reply] [d/l] [select] |
| [reply] [d/l] [select] |
Thats my whole point. The example does not use STDIN, but mktrace does require the input via STDIN. That being the case, how can I get mktrace the info via STDIN?
| [reply] |
Greetings all,
Okay This is only an idea based on some of the things I have seen elsewhere... again this is just an thought.
Could you in your perl script open a filehandle to a run of your C program?
Something similar to :
open (MAIL, "| /usr/sbin/sendmail -t") || die "no mail for you!";
but instead of sendmail it would be your C program
open (CPROG, "| /path/to/your/program") || die;
then pipe all the filenames to the filehandle you created?
or am I way off here?
Just a thought...
-injunjoel | [reply] [d/l] [select] |