Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get result output? #1113

Open
dshumakerUT opened this issue Apr 27, 2022 · 2 comments
Open

How to get result output? #1113

dshumakerUT opened this issue Apr 27, 2022 · 2 comments

Comments

@dshumakerUT
Copy link

When I do something like this in a task:

$result = $this->_exec('vendor/bin/blt --version | \grep \^BLT');

I see the output of that "bash" command printed to the terminal. I'm guessing this is via ( https://github.com/consolidation/robo/blob/3.x/src/Result.php#L274)

So the resulting output is buried in there somewhere in the result. However it seems protected.

When I try

$result = $this->_exec('vendor/bin/blt --version | \grep \^BLT');
$bltVersion = $result->output;

or

$result = $this->_exec('vendor/bin/blt --version | \grep \^BLT');
$bltVersion = $result->getOutput();

I tried this because it seems like robo is using the symfony methods & classes like ( https://symfony.com/doc/current/components/process.html#streaming-to-the-standard-input-of-a-process )

I get errors saying that output and getOutput are protected? And I guess that is ok, but it's a bit counter intuitive.

Isn't Robo supposed to be a task runner where it's primary function is to interact with and run shell commands ?
If so then i kinda hoped it would be easier to get at the results of executed shell commands. Why are they protected?

Is there a nifty way to get at this output? I didn't see any examples in the docs.

Next I guess I'll try something like what's mentioned here ( #1097 (comment) )

CommandResult::data($result['my_list']);

I'm not sure if this is related to ( #858 ) but it kind of sounds similar.

Is there an easy way to get at the commands output? Sorry if I missed it in the documentation.

@dgrothaus-mc
Copy link

This comment helped me getting the output of a command. Perhaps it's what you're looking for.

#382 (comment)

@greg-1-anderson
Copy link
Member

One thing I want to emphasize is that you do not need to use Robo exclusively in programs that use Robo. Robo is great for a task runner, but it's not a great wrapper around exec or Symfony Process. These tasks exist, in case you need to throw an exec into a chain of tasks; if you're just trying to run a program to get some data to set up your tasks, you're probably better off just using one of those lower level APIs directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants