I do not normally look at PHP questions because I have no interest in PHP and at most passing familiarity with it. But on review I voted to close this question as Needs Details or Clarity. Since "unclear" is also part of the list of reasons offered on the tooltip for downvoting questions, I can guess that others felt the same way.
It arguably also doesn't have a proper MRE, and thus Needs Debugging Details. Finally, since the issue seems so fundamental (you appear to be trying to use one specific bit of library functionality to launch another process, and want to do something specific with the output of that process), that the question ought to be a Duplicate once properly understood. But again, I don't know the PHP canonicals so I can't help with that.
I am calling composer show
from my plugin like this
This doesn't give proper context for the problem. What is the plugin plugging into? (Is the fact that it's a plugin, actually relevant to the problem? Can you reproduce the problem more directly?) What's "composer" and what does it have to do with PHP? (Would the problem be the same if you were trying to run any other arbitrary program in the same way?) Someone else edited to add tags based on subject matter expertise and guesswork. We shouldn't have to do that. We shouldn't have to read tags in order to understand the basic context of a problem, either.
[code]
What's $this
? Why should it have a getApplication
, which has a doRun
? Rather than trying to have the context of the code be implicit according to the framework you say you are using (you don't even say that! Someone else had to guess tags to add!), please show code that includes necessary imports etc. and enough setup to where someone else could copy and paste the code, without adding or changing anything, to see the exact problem, directly.
How could I separate stdout and stderr or suppress stderr completely?
This doesn't clearly explain what went wrong when trying the code. I guess you mean that stdout and stderr of the called process were intermingled in some way. We should be able to see a proper example of what happens when you try using the code, and what should happen instead; and it should be clear how that differs.
It also isn't clear to me how you come to this conclusion that there is a problem at all: by examining $showOutput
after the call (and how, exactly), by considering what you see in the terminal, or something else.
I just need the JSON.
This makes no sense by itself. My first thought was that you want to know what to use to initialize $args
, so that when the rest of the code runs, you can specifically extract the stdout. Of course, that syntax isn't JSON, but I can imagine people describing it that way. But on a closer read, I assume you mean something like "the stdout of this process will be JSON data and I want to capture it in $showOutput
. This should be made clear by framing the question with some minimal context (maybe something like "I want to use ... to call composer show
, which should produce JSON output on stdout. I have this code: ... I expected to get a result like: ... but instead [$showOutput
has the wrong value / something shows up in the terminal that I want to suppress / etc.]").