Skip to contentSkip to conversation

process: Do not mix stderr with stdout

PATCH Anton Mikanovich 3 participants 5 messages Dec 17, 2021 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 13 lines · Anton Mikanovich

We should not redirect stderr to stdout if we need to get separated stdout and stderr contents from Popen.communicate() later.

---
  lib/bb/process.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/process.py +0 -0
index d5a1775f..af5d804a 100644

lib/bb/process.py class Popen(subprocess.Popen): · line 66

Quoted 8 lines
lib/bb/process.py +1 -1
@@ -60,7 +60,7 @@ class Popen(subprocess.Popen):
          "close_fds": True,
          "preexec_fn": subprocess_setup,
          "stdout": subprocess.PIPE,
-        "stderr": subprocess.STDOUT,
+        "stderr": subprocess.PIPE,
          "stdin": subprocess.PIPE,
          "shell": False,
      }

Can anyone review this change to proof the fix is correct?

Signature · 8 lines
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov
#2 lore raw

It helps if you describe the problem that occurs without the patch and how it can be observed.

Ale

Quoted 47 lines · Anton Mikanovich
Quoted 13 lines · Anton Mikanovich

We should not redirect stderr to stdout if we need to get separated stdout and stderr contents from Popen.communicate() later.

---
  lib/bb/process.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/process.py +0 -0
index d5a1775f..af5d804a 100644

lib/bb/process.py class Popen(subprocess.Popen): · line 66

Quoted 8 lines
lib/bb/process.py +1 -1
@@ -60,7 +60,7 @@ class Popen(subprocess.Popen):
          "close_fds": True,
          "preexec_fn": subprocess_setup,
          "stdout": subprocess.PIPE,
-        "stderr": subprocess.STDOUT,
+        "stderr": subprocess.PIPE,
          "stdin": subprocess.PIPE,
          "shell": False,
      }

Can anyone review this change to proof the fix is correct?

--
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13190):
https://lists.openembedded.org/g/bitbake-devel/message/13190
Mute This Topic: https://lists.openembedded.org/mt/87592650/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw
Quoted 43 lines · Alexander Kanavin

It helps if you describe the problem that occurs without the patch and how it can be observed.

Ale

On Fri 17. Dec 2021 at 19.43, Anton Mikanovich <[email protected] <mailto:[email protected]>> wrote:

08.12.2021 19:57, Anton Mikanovich wrote:
> We should not redirect stderr to stdout if we need to get separated > stdout and stderr contents from Popen.communicate() later. >
> Signed-off-by: Anton Mikanovich <[email protected] <mailto:[email protected]>>
> ---
>   lib/bb/process.py | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/bb/process.py b/lib/bb/process.py
> index d5a1775f..af5d804a 100644
> --- a/lib/bb/process.py
> +++ b/lib/bb/process.py
> @@ -60,7 +60,7 @@ class Popen(subprocess.Popen):
>           "close_fds": True,
>           "preexec_fn": subprocess_setup,
>           "stdout": subprocess.PIPE,
> -        "stderr": subprocess.STDOUT,
> +        "stderr": subprocess.PIPE,
>           "stdin": subprocess.PIPE,
>           "shell": False,
>       }

Can anyone review this change to proof the fix is correct?

--
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov

Quoted 15 lines

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13190):
https://lists.openembedded.org/g/bitbake-devel/message/13190
<https://lists.openembedded.org/g/bitbake-devel/message/13190>
Mute This Topic:
https://lists.openembedded.org/mt/87592650/1686489
<https://lists.openembedded.org/mt/87592650/1686489>
Group Owner: [email protected] <mailto:bitbake-devel%[email protected]>
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub
<https://lists.openembedded.org/g/bitbake-devel/unsub>
[[email protected] <mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-

Hello, Alexander

As I've already mentioned in description the problem is mixing both stderr and stdout of the command to stdout output variable when using bb.process.run() Here are minimal steps to reproduce:

$ cat /usr/bin/test.sh
#!/bin/sh
echo "This is stderr" >&2
echo "This is stdout"

Task:

python do_test() {
    out,err = bb.process.run('test.sh') bb.warn('STDOUT:', out or 'EMPTY') bb.warn('STDERR:', err or 'EMPTY') }
addtask do_test

Result without the patch:

WARNING: do_test: STDOUT:This is stderr This is stdout
WARNING: do_test: STDERR:EMPTY

So both stdout and stderr of test.sh were filled to out variable.

Result after the patch:

WARNING: do_test: STDOUT:This is stdout
WARNING: do_test: STDERR:This is stderr

Signature · 8 lines
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov
#4 lore raw

Thanks, looks like the issue is real, so the patch should go in unless there are other concerns.

Alex

Quoted 100 lines · Anton Mikanovich

17.12.2021 19:54, Alexander Kanavin wrote:

It helps if you describe the problem that occurs without the patch and how it can be observed.

Ale

Quoted 46 lines · Anton Mikanovich
Quoted 13 lines · Anton Mikanovich

We should not redirect stderr to stdout if we need to get separated stdout and stderr contents from Popen.communicate() later.

---
  lib/bb/process.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/process.py +0 -0
index d5a1775f..af5d804a 100644

lib/bb/process.py class Popen(subprocess.Popen): · line 66

Quoted 8 lines
lib/bb/process.py +1 -1
@@ -60,7 +60,7 @@ class Popen(subprocess.Popen):
          "close_fds": True,
          "preexec_fn": subprocess_setup,
          "stdout": subprocess.PIPE,
-        "stderr": subprocess.STDOUT,
+        "stderr": subprocess.PIPE,
          "stdin": subprocess.PIPE,
          "shell": False,
      }

Can anyone review this change to proof the fix is correct?

--
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13190):
https://lists.openembedded.org/g/bitbake-devel/message/13190
Mute This Topic: https://lists.openembedded.org/mt/87592650/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Quoted 1 line

Hello, Alexander

As I've already mentioned in description the problem is mixing both stderr and stdout of the command to stdout output variable when using bb.process.run()
Here are minimal steps to reproduce:

$ cat /usr/bin/test.sh
#!/bin/sh
echo "This is stderr" >&2
echo "This is stdout"

Task:

python do_test() {
    out,err = bb.process.run('test.sh')
    bb.warn('STDOUT:', out or 'EMPTY')
    bb.warn('STDERR:', err or 'EMPTY')
}

addtask do_test

Result without the patch:

WARNING: do_test: STDOUT:This is stderr
This is stdout
WARNING: do_test: STDERR:EMPTY

So both stdout and stderr of test.sh were filled to out variable.

Result after the patch:

WARNING: do_test: STDOUT:This is stdout
WARNING: do_test: STDERR:This is stderr

--
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov