title: Run Windows CMD commands via Python
body: <p>I want to create a folder with symlinks to all files in a large directory structure. I used <code>subprocess.call(["cmd", "/C", "mklink", linkname, filename])</code> first, and it worked, but opened a new command windows for each symlink. </p>
  
  <p>I couldn't figure out how to run the command in the background without a window popping up, so I'm now trying to keep one CMD window open and run commands there via stdin:</p>
  
  <pre><code>def makelink(fullname, targetfolder, cmdprocess):
      linkname = os.path.join(targetfolder, re.sub(r"[\/\\\:\*\?\"\&lt;\&gt;\|]", "-", fullname))
      if not os.path.exists(linkname):
          try:
              os.remove(linkname)
              print("Invalid symlink removed:", linkname)
          except: pass
      if not os.path.exists(linkname):
          cmdprocess.stdin.write("mklink " + linkname + " " + fullname + "\r\n")
  </code></pre>
  
  <p>where</p>
  
  <pre><code>cmdprocess = subprocess.Popen("cmd",
                                stdin  = subprocess.PIPE,
                                stdout = subprocess.PIPE,
                                stderr = subprocess.PIPE)
  </code></pre>
  
  <p>However, I now get this error:</p>
  
  <pre><code>File "mypythonfile.py", line 181, in makelink
  cmdprocess.stdin.write("mklink " + linkname + " " + fullname + "\r\n")
  TypeError: 'str' does not support the buffer interface
  </code></pre>
  
  <p>What does this mean and how can I solve this?</p>