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

Capturing the command output via Robo does not work anymore (regression in 7.0.0) #1149

Closed
amenk opened this issue Mar 15, 2023 · 15 comments · Fixed by #1151
Closed

Capturing the command output via Robo does not work anymore (regression in 7.0.0) #1149

amenk opened this issue Mar 15, 2023 · 15 comments · Fixed by #1151
Labels

Comments

@amenk
Copy link
Contributor

amenk commented Mar 15, 2023

We are using Robo v4 and n98-magerun2 in the following way:

private function magerunTwoWithResult(string $command): string
{
    return $this->taskExec(sprintf('php8.1 %s %s', '/usr/local/bin/n98-magerun2', $command))
        ->printOutput(false)
        ->run()
        ->getMessage();
}

Expected behaviour

When calling the above function in the RoboFile for example with deploy:mode:show we get the output (verified with 6.1.1), but with 7.0.0 we get an empty result. Robo v3.0.10 and magerun2 v7.0.0 show the same problem.

Steps to reproduce the issue

  1. Execute the above code in a robo file
  2. result is not empty

Workaround

When calling bin/magento instead of magerun2 it works.

Was there anything changed in the TTY handling or something like this which could cause this issue?

@amenk amenk added the bug label Mar 15, 2023
@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

@amenk yes, we call all Core commands now as sub-process (via Symfony Process).
See here:

$process = Process::fromShellCommandline(

Sadly I will not be available until next week to do serious work on n98-magerun2 to fix this issue.

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

The output is passed to the output of the command.

$process->run(function ($type, $buffer) use ($output) {
    $output->write($buffer);
});

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

I just did a test in the Magerun dev box with this RoboFile.

<?php
/**
 * This is project's console commands configuration for Robo task runner.
 *
 * @see https://robo.li/
 */
class RoboFile extends \Robo\Tasks
{
    private function magerunTwoWithResult(string $command): string
    {
        return $this->taskExec(sprintf('php8.2 %s %s', './n98-magerun2.phar --root-dir=/opt/magento-test-environments/magento_2_4_6/', $command))
            ->printOutput(false)
            ->run()
            ->getMessage();
    }

    public function deployModeShow()
    {
        return $this->magerunTwoWithResult('deploy:mode:show');
    }
}

I did a test with "bin/n98-magerun2" and the phar file.
Both are working.

What I currently see is that we do not prepend the PHP interpreter to the bin/magento call.
Maybe that's an issue if several PHP versions are used.

image

@amenk
Copy link
Contributor Author

amenk commented Mar 15, 2023

Not sure if the output comes from robo or from magerun. Can you try

var_dump( $this->magerunTwoWithResult('deploy:mode:show') );

The PHP interpreter is not that important anymore, we use that only temporarily.

We are on Magento 2.4.5-p1 + PHP8.1 by the way

@ktomk
Copy link
Collaborator

ktomk commented Mar 15, 2023

@amenk: Please try and see if it works:

sprintf('php8.1 %s %s | cat', ...
                      ##### 

and please share which operating system and shell.

This might be similar: composer/composer#9454 (comment)

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

@ktomk Good finding. We have also a similar issue for the db dump in #929 which is a sub-process like here.

@amenk
Copy link
Contributor Author

amenk commented Mar 15, 2023

@ktomk
| cat does not help.
default shell is bash on Ubuntu 22.04

@ktomk
Copy link
Collaborator

ktomk commented Mar 15, 2023

@amenk Thanks, that's what I thought. Can you try to invoke robo prefixed with the unbuffer command (part of the expect package)? If that works, this strongly points to TTY handling of the Symfony Console component in use and a potential solution could be similar as in Composer.

@amenk
Copy link
Contributor Author

amenk commented Mar 15, 2023

@ktomk unbuffer works if I prefix the command in Robo:

return $this->taskExec(sprintf('unbuffer php8.1 %s %s', $this->n98Magerun2Executable, $command))

I guess this is what you meant

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

We use the TTY mode of the Symfony Process depends if the tool is started interactive or non-interactive.
https://symfony.com/doc/5.4/components/process.html#using-tty-and-pty-modes

There is also a Pty Mode. I have not tested this, because I had not had any issues.

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

I changed setTty to setPty. Both work in the debian based docker container. Would be interesting to know where the environment differs. Currently I am not able to reproduce the issue.

@cmuench
Copy link
Member

cmuench commented Mar 15, 2023

@ktomk do you think we handle that in n98-magerun2 in any way?

@cmuench
Copy link
Member

cmuench commented Mar 16, 2023

@amenk have you tried with --no-interaction option?

@amenk
Copy link
Contributor Author

amenk commented Mar 16, 2023

--no-interaction works like a charm and makes a lot of sense in this case.
We can go with changing our scripts in this way.

From my point of view we could close this issue.
Eventually it should be added to some release notes or so...

Thank you very much!

@ktomk
Copy link
Collaborator

ktomk commented Mar 16, 2023

@ktomk do you think we handle that in n98-magerun2 in any way?

Same as composer likely, this is how I read the recent testing (thanks @amenk).

This works because of $input->isInteractive() here:

$process->setTty($input->isInteractive());

For regression testing it would be good to have a branch with a robo task that demonstrates it. @amenk, would it be easy to create and push? If all goes well it should be easy to fix and then we would not need to provide addition read-me/release notes on such easy to miss/puzzling behaviour (by behaviour also a regression).

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

Successfully merging a pull request may close this issue.

3 participants