question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output of os.system, subprocess.call goes to command prompt instead of qtconsole, on Windows 10, Open Suse

See original GitHub issue

Problem Description

When running os.system or subprocess.call on Windows 10, no output is produced in qtconsole. Instead the output goes to the Anaconda Prompt console or, if qtconsole was started from the start menu, is simply discarded.

The same issue is reproducible with ipython qtconsole and and the sypder IDE, where this issue was originally reported (https://github.com/spyder-ide/spyder/issues/14783), but declared an depenency issue.

When running bare-bones consoles (ipython, python), the issue does not appear, presumably because everything is displayed in the same cmd.exe window.

On OpenSuse the issue occurs likewise. If the console is started from a terminal window, that terminal will receive the output of the commands. When originally posted, I thought I couldn’t reproduce the issue on Linux.

Qt Console

image

As a component in Spyder

image

What steps reproduce the problem?

  1. Run jupyter qtconsole from the Anaconda prompt.
  2. In the qtconsole type import os; os.system(r"mkdir C:\tmp\demo & dir C:\tmp\demo")

What is the expected output? What do you see instead?

The expectation is to see the output in the graphical console, together with the output of print or sys.stdout.write.

Instead the output is displayed in the command prompt window.

Potentially relevant package versions

  • Python version: 3.8.5
  • Qt version: 5.9.7
  • PyQt version: 5.9.2, PyQt5: 5.12.3
  • QtConsole: 5.0.2
  • OS: Windows 10, Version 2004 (OS Build 19041.804)
DEPENDENCY REPORT OF SPYDER
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=7.6.0                 :  7.20.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  22.0.1 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.8.0 (OK)
pygments >=2.0                  :  2.7.4 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.2;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.3.0             :  0.3.0 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=5.0.1               :  5.0.2 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.4 (OK)
setuptools >=39.0.0             :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                  :  3.4.3 (OK)
spyder_kernels >=1.10.1;<1.11.0 :  1.10.1 (OK)
textdistance >=4.2.0            :  4.2.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  1.0.2 (OK)
zmq >=17                        :  20.0.0 (OK)

cython >=0.21                   :  0.29.21 (OK)
matplotlib >=2.0.0              :  3.3.4 (OK)
numpy >=1.7                     :  1.19.2 (OK)
pandas >=1.1.1                  :  1.2.1 (OK)
scipy >=0.17.0                  :  1.6.0 (OK)
sympy >=0.7.3                   :  1.7.1 (OK)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
impact27commented, Mar 1, 2021

PR spyder-ide/spyder#1478 solves that problem, but only for consoles started from spyder. Also, if another client connects to the same console, it wouldn’t recieve the messages either.

The ipython kernel creates a new sys.stdout. Any output that is written to sys.stdout or sys.stderr, for example using the print function, is sent to the client. The problem is that any non-python code is not aware of the new sys.stdout and uses the regular cout. On UNIX you can pipe that back to sys.stdout (wurlitzer does that) but I don’t know of any way to do that on windows. In spyder we can control the process for the kernel (if it is started from spyder) and therefore the cout can be printed in the console (spyder-ide/spyder#14783) but this is not going through the regular ipython mechanisms. That means that the cout is not sent to any other clients.

0reactions
ccordoba12commented, Feb 26, 2021

Wurlitzer only works on Posix systems (sorry if I wasn’t clear enough about it).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python System Command - os.system(), subprocess.call()
Using subprocess. check_output() function we can store the output in a variable.
Read more >
Hiding console output produced by os.system - Stack Overflow
To answer the question based on its title in the most generic form: To suppress all output from os.system() , append >/dev/null 2>&1...
Read more >
Calling Shell Commands from Python: OS.system vs ...
Calling Shell Commands from Python: OS.system vs Subprocess ... As os.sys, the function subprocess.call returns the return value as its ...
Read more >
How to implement the AutoComplete function found in ... - Quora
A simple shell is a program that takes a string input, performs an OS call to run this input string and returns the...
Read more >
how to install express in console Code Example
What is Node.js, Express.js? ... is npm express? ... Which command is correct to install the express package using Node Package Manager? ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found