0

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?

Mark
  • 3,609
  • 1
  • 22
  • 33
Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • so your delimiter is actualy `\n` as new line, instead of whitespace (don't know how much interesting is that HTML does not understand new lines, if they are not explicitly said by a tag, that breaks the line. So if there are not
    , the web page will not break the lines)
    – Royal Bg Jan 15 '14 at 16:58
  • I've tried to do expode it with the `"\n"` as suggested [here](http://stackoverflow.com/a/3997362/1081396) but It is not working so I'm not sure how it is actually separating the lines internally. – Alvaro Jan 15 '14 at 17:00
  • So what's the output when you explode on `\n` or `\n\r` ? – Royal Bg Jan 15 '14 at 17:01
  • Ok, the problem is the use of `system`. I changed it for `exec` and now it is returning it in an array . – Alvaro Jan 15 '14 at 17:05

1 Answers1

0

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.

Community
  • 1
  • 1
Alvaro
  • 40,778
  • 30
  • 164
  • 336