This question has already been answered:
- Redirecting terminal output to variable 3 responses
- Byte when printing the output of an external command 2 response
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? *
subprocess.run( )- Alex Titov