This question has already been answered:

There is such code:

command = "ipconfig" answer = os.system(command) 

In the PyCharm console, the cmd response appears:

 DNS-   䨪        祭   . . . . . : IPv4-    . . . . . . . . . . . . : 192.168.1.4   ᪠       . . . . . . . . . . : 255.255.255.0  ᭮       . . . . . . . . . : 192.168.1.1 Ethernet adapter       祭           쭮    :     ﭨ   । . . . . . . . . :  ।    ।         㯭 . DNS-   䨪        祭   . . . . . :  㭭            Teredo Tunneling Pseudo-Interface:     ﭨ   । . . . . . . . . :  ।    ।         㯭 . DNS-   䨪        祭   . . . . . :  㭭                  祭           쭮    * 12:     ﭨ   । . . . . . . . . :  ।    ।         㯭 . DNS-   䨪        祭   . . . . . : Process finished with exit code 0 

I need to write all this into the answer variable. But instead of outputting cmd, it is simply written with a zero "0".

I understand this this zero: Process finished with exit code 0

I need to write in answer exactly the contents of the response cmd

*and further. What is wrong with the encoding? Why rus characters are not displayed? *

Reported as a duplicate by jfs python Nov 3 '17 at 6:57 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Use subprocess.run( ) - Alex Titov

1 answer 1

Try this:

 # coding utf-8 # Предыдущая строка меняет кодировку на utf-8 import subprocess command = "ipconfig" output = subprocess.check_output(command) print ouput