perl: capturing STDOUT- logfile ends up binary

I wrote a script that feeds data into an exe program called ctffind. The exe program outputs a bunch of data to the screen which I'm trying to capture in a logfile.

Here's what I'm using right now

my $logout = logfile 
open STDOUT, '>>', "$logout";
open my $PIPE1, '|-', '/opt/ctf/ctffind3_mp.exe' or die $!;

It works outputting everything that appeared on the screen into logfile.

If I more $logfile the file displays as expected it's about 5000 lines long and has about 50 lines that contain the string "final values". In my next step I do grep "final values" logfile it thinks logfile is a binary file and doesn't work instead it returns:

Binary file logfile matches

How do set it so that logfile is properly encoded? ctffind.exe is also generating binary files while it runs, is this part of the problem?


I have found two different ways to resolve the problem, thanks to commenters' suggestions:

  1. One can change the grep logfile to grep -a logfile.

  2. One can use strings logfile logfile2 to make a usable version of the logfile.

Need Your Help

Using translation strings in componentlinks

tridion tridion-2011

I've been trying to solve this problem since this morning, and I know I'm missing something obvious here but I can't seem to find it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.