Reputation: 10451
I am calling find from a perl script like this:
my $one_file = `find $search_dir -name "\*.$refinfilebase.search" -print | head -n 1`;
If I execute it from the shell, I get no error. Also, it returns the right value to $one_file, but I get this on the prompt:
find: write error: Broken pipe
Why would that be? How can I get rid of this find: write error: Broken pipe message?
Upvotes: 4
Views: 3056
Reputation: 67910
Why are you using find
and head
in backticks, when there are perl ways to handle it? I.e.:
my @files =
<$refinfilebase.search>
I would only recommend using backticks when you're absolutely sure about what you are doing, and it seems to me that you are not. Heck, you could make your current attempt work by simply doing this:
my @files = `find $search_dir -name "\*.$refinfilebase.search" -print`
my $one_file = $files[0];
Upvotes: 3
Reputation: 2719
You could try this (although I did not manage to reproduce your error message using the code you posted, so perhaps this error-free version of mine might give you an error message as well...):
my $file = `find $search_dir -name "\*.ssf" -print -exec head -n 1 {} \\;`;
Here's some sample output I got from a test run:
./tmp1.ssf
HEADER PROTEIN 21-FEB-11 1PDB
HTH
Upvotes: 1
Reputation: 4070
This "error" is perfectly normal and is to be expected.
head
which quits after getting one line of input.find
command tries to write its remaining lines to a pipe that has no one listening anymore (head
is dead).find
will throw an error.If you want to get rid of the error just do:
my $file = `find .... 2>/dev/null | head -n 1`;
This will keep the utterly predictable error from find from getting to your terminal (since neither the backticks nor the pipe into head
touch stderr, which is where that error is being printed).
Upvotes: 4