0

So I am learning how to use cmd from python and tried to do this:

import subprocess
proc = subprocess.Popen('cmd.exe', stdin = subprocess.PIPE,  encoding = 
'utf8', stdout = subprocess.PIPE)
stdout, stderr = proc.communicate('dir c:\\')
print(stdout)

This apparently does not work as this is what i recieve:

Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\User\AppData\Local\Programs\Python\Python36-32>More?

WHy only one line and not what was commanded?

1 Answers1

0

The answer to this related question suggests a better approach to communicating with the shell on windows:

import subprocess
result = subprocess.check_output('cmd /k dir c:\\', shell = True)
Nathan Vērzemnieks
  • 5,495
  • 1
  • 11
  • 23