AggressiveFish Posted October 24, 2018 Share Posted October 24, 2018 I'm using "php -l scriptName.php". When I run this when there are errors I get two lines back - one starting with "PHP Parse error:...." and the other the exact same thing except minus the leading "PHP ". Is there a way to suppress the first line that gets printed? Please don't suggest fixing the code so there are no errors. The purpose of using the syntax checker is for a learning to program application. The code needs to check a user's input when they make changes and I only need the second error line that gets displayed (as it looks to be what is returned from the command - STDOUT). The first line appears to print from inside the command. I run the command from within a script and the value from the command is returned to the calling script but it's the second line that is "returned", the first line just prints. Hopefully that makes sense. I just need to somehow suppress the first error line. On successful syntax checking I get the desired results - one line of output is received. Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 24, 2018 Share Posted October 24, 2018 I already answered you in the other forum you cross-posted on and cited the manual explanation of how it works. That's just what it does. Quote Link to comment Share on other sites More sharing options...
AggressiveFish Posted October 24, 2018 Author Share Posted October 24, 2018 The other forum is, how to put it, not that well thought out considering if you are a new user you have only a limited number of posts? I went to respond and couldn't. So I decided to go to another forum and I can't quite continue from where I left off on that one. You're telling me there is no solution for suppressing the first error message? So there are essentially two of the same things getting reported. There has to be some sort of workaround if not a straight up solution (i.e. flag). Quote Link to comment Share on other sites More sharing options...
requinix Posted October 24, 2018 Share Posted October 24, 2018 I only see one message. PHP Parse error: syntax error... in file.php on line whatever Errors parsing file.php Do you maybe have XDebug installed and it's doing its own message? Quote Link to comment Share on other sites More sharing options...
AggressiveFish Posted October 24, 2018 Author Share Posted October 24, 2018 Lol not intentionally ? PHP Parse error: syntax error, unexpected '=' in C:\directory1\directory2\test.php on line 4 Parse error: syntax error, unexpected '=' in C:\directory1\directory2\test.php on line 4 Errors parsing C:\directory1\directory2\test.php My apologies though. I was thinking the output printed was the same line twice (with the second line just missing the "PHP " start) but now I see the additional "Errors" line at the end. When I run the command in the following way : my $variableFeedback = qx "php -l C:\directory1\directory2\test.php"; I receive the above feedback. The variable $variableFeedback actually holds the string from "Parse error" onwards. The first line above is actually generated somewhere within the program call. So if you run a script with garbage / errors you only get the portion I'm looking for? Interesting. How can I go about looking for what is causing this? Whether XDebug (sorry, not familiar - fairly new to PHP) is installed or not? I had hoped there was a flag I could just add onto the -l that turned off some setting. Thank you for the reply. If you can help out a bit further I'd appreciate it. ? Quote Link to comment Share on other sites More sharing options...
AggressiveFish Posted October 24, 2018 Author Share Posted October 24, 2018 I just ran "php --re xdebug" and it appears it isn't installed. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 24, 2018 Share Posted October 24, 2018 What if you use the -n option? my $variableFeedback = qx "php -n -l C:\directory1\directory2\test.php"; Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 24, 2018 Share Posted October 24, 2018 (edited) Here is what the manual says about it. Quote -l --syntax-check Provides a convenient way to perform only a syntax check on the given PHP code. On success, the text No syntax errors detected in <filename> is written to standard output and the shell return code is 0. On failure, the text Errors parsing <filename> in addition to the internal parser error message is written to standard output and the shell return code is set to -1. Edited October 24, 2018 by benanamen Quote Link to comment Share on other sites More sharing options...
kicken Posted October 24, 2018 Share Posted October 24, 2018 One of the lines comes from the engine is controlled by the display_errors ini setting. These are printed on STDOUT. The second line is from the -l setting showing the specific error it encountered. These are printed on STDERR. So, you can do two different things. 1) You could turn off display_errors to prevent one of the messages on STDOUT. You can do this by passing -d display_errors=0 2) You could redirect either STDOUT or STDERR to /dev/null (or elsewhere) to ignore or capture them specifically. 2 Quote Link to comment Share on other sites More sharing options...
AggressiveFish Posted October 25, 2018 Author Share Posted October 25, 2018 kicken .... actually a very awesome answer and so very, very close to what I'm looking for. If I run with the flag you have above the "PHP" starting string gets printed to the STDOUT but the other one doesn't. The thing is I don't have any control over the string but the string that is getting returned from the command I can because I assign it to a variable first. Is there a parameter to suppress the "PHP" starting string but leave the non-PHP starting line? That would be the optimum scenario. If it cannot be done do you know off hand a quick and easy way to switch the active directory I'm executing from? I supply the full path to the php script but I don't want the user seeing the full path in the error returned. I either need the error returned where I can null out that portion of the path in the variable OR I supply the file name only but I need to be execute from that directory then. Hopefully that makes sense :-) Thanks so much though, a very informative and useful response. Quote Link to comment Share on other sites More sharing options...
AggressiveFish Posted October 25, 2018 Author Share Posted October 25, 2018 Never mind, I did my own investigation (only after you pointed out the -d flag) and got the expected results. Thanks so much. I used "-d log_errors=0" and it's working as I want. Thanks so much for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.