I have matlab function that calls a Perl script which converts a large text file to binary for use in Matlab. See here for Perl script details: Parsing unsorted data from large fixed width text
My Matlab function looks something like this
function convertMyData(dataFileName)
%Do some checks on the data
disp('Done Checking Stuff!');
%Process data file with Perl
perl('myPerlScript.pl',dataFileName)
% More Processing on the Binary output from Perl
disp('All Done!');
In the perl script are some print statements showing the progress of the script since it can take several minutes to convert. Something like this:
while ($line = <INFILE>) {
if ($lineCount % 100000 == 0){ #Display Progress every 100,000 lines
print "On Line: ".$lineCount."\n";
}
#PROCESS LINE DATA HERE
$lineCount ++;
} # END WHILE <INFILE>
print "Finished Reading: ".$lineCount." Lines\n";
The problem is that in Matlab all of my “On Line: XXXXX” print statements just get dumped to Matlab’s default ans variable once the script completes instead of actually displayed at the prompt like Matlab’s disp() function.
So how (if possible) do you get an external program’s output to show up at the Matlab prompt while it is running?
I don’t think you can do it. MATLAB passes the control to perl interpreter and then just get back the results.
There is one workaround that worked for me. First add
local $|=1;inside your perl script to turn on STDOUT autoflush. Before any output to STDOUT. (See, for example, here for more details on flushing buffer.) Then call perl usingsystemfunction:Double-quotes are important if your perl interpreter is located in a path with spaces.