Question

I have this Batch file which looks for a string through the files contained in a folder.

@echo off
pushd "%1"
findstr /m /C:%2 *
popd

If I execute that from a command line, it prints the names of the files containing the searched string.

From PHP, the Batch file is being executed with this command:

system("cmd /c C:/path/myFile.bat C:/path toSearch", $returned);

The problem is that the $returned element is a string instead of an array. Each of its elements is separted by a white space.

I was thinking of exploding it but it's not possible as some files contain also white spaces.

What is interesting is that in the source code of the page in which I print the resulting string each of the elements is in fact is one line, like so:

element1
second element
third element

But the resulting HTML code is this way:

element1 second element third element

Any suggestion?

Was it helpful?

Solution

Solved.

The problem was that system automatically prints the output of the executed file. I changed it for exec and now an array is being returned in the $returned variable.

exec("cmd /c C:/path/myFile.bat C:/path toSearch", $returned);

More info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top