S
S
stasboiko2020-07-15 17:55:03
PHP
stasboiko, 2020-07-15 17:55:03

Why doesn't the exec() function in php always return the correct result when getting the number of lines in a file?

there is a code that has been working for many years without problems and complaints:

$countRows = intval(exec("/usr/bin/wc -l fileName.csv"));

this code returns the number of absolutely all lines in the file (even if there are empty lines between the data lines)
Today I downloaded a file from a MAC in which there are 60 entries
These entries go through one (that is, the first line with data, and the second empty)
That is 30 rows of data and 30 empty rows

$countRows in this case is 30 (file saved via MAC)
I changed one value in the file (removed/replaced it doesn't matter) and saved in Linux and in this case $countRows is 60
I also did the same on windows and got 60
file format did not change
This function has been working on the site for 8 years and for the first time it returned a value equal to not the entire number of lines in the file (but only real records / empty lines were not counted)

This error (incorrect count of the number of lines in the file) occurs only when the file is saved with MAC and there are empty lines in this file
I don't know how to replace this function because before we ran the whole file, counted the number of lines BUT it is very long especially when there are several million records in the file
I had to abandon this idea

What can replace this function?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question