title: system() argument 1 must be string without null bytes, not str
body: <p>I have the following Python code running on Python version 2.7 and Windows.</p>
  
  <p>The code basically grabs the URL from my active Google Chrome tab, then runs and passes the URL as an argument to a Windows batch file.</p>
  
  <pre><code>import os
  import win32gui
  import win32con
  
  hwnd = win32gui.GetForegroundWindow()
  
  omniboxHwnd = win32gui.FindWindowEx(hwnd, 0, 'Chrome_OmniboxView', None)
  
  def getWindowText(hwnd):
      buf_size = 1 + win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0)
      buf = win32gui.PyMakeBuffer(buf_size)
      win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buf_size, buf)
      return str(buf)
  
  url = getWindowText(hwnd)
  
  exe = 'run.bat "%s"' %(url)
  
  os.system(exe)
  </code></pre>
  
  <p>However, running the code from the command line throws the following error: </p>
  
  <pre><code>TypeError: system() argument 1 must be string without null bytes, not str
  </code></pre>
  
  <p>Is there something that I'm missing out here?</p>
  
  <p>EDIT: Manually inputting a URL string works, i.e. replacing</p>
  
  <pre><code>url = getWindowText(hwnd)
  </code></pre>
  
  <p>with </p>
  
  <pre><code>url = "https://stackoverflow.com/questions/39976936/"
  </code></pre>
  
  <p>works, so it seems that the problem lies with how the code grabs the URL string from the window. I took the code from <a href="https://stackoverflow.com/questions/11645123/how-do-i-get-the-url-of-the-active-google-chrome-tab-in-windows">How do I get the URL of the active Google Chrome tab in Windows?</a> and I'm not familiar with it at all. Is there an alternative way to grab the URL?</p>