title: Python on Windows - Opening a browser URL with parameters in powershell
body: <p>I have an existing, working Python script that uses AppleScript on Mac that runs UI vision automation scripts using the browser of my choice. An example URL is:</p>
  <pre><code>file://[path_to_automation_file]?direct=1&amp;savelog=[log_file_name]&amp;cmd_var1=[argument]
  </code></pre>
  <p>The script uses subprocess.check_output to run the applescript command. An example:</p>
  <pre><code>subprocess.check_output(&quot;osascript -e 'tell application \&quot;Google Chrome\&quot; to open location \&quot;[url]\&quot;&quot;, shell=True)
  </code></pre>
  <p>I need to extend this script to work in Windows as well and I found that I can use the following Powershell command:</p>
  <pre><code>Start-Process -FilePath chrome -ArgumentList 'file://[path_to_automation_file]?direct=1&amp;savelog=[log_file_name]&amp;cmd_var1=[argument]'
  </code></pre>
  <p>This works perfectly fine when I run it on Powershell directly. But when I move this into the subprocess.check_output call like this:</p>
  <pre><code>subprocess.check_output(&quot;Powershell Start-Process -FilePath chrome -ArgumentList 'file://[path_to_automation_file]?direct=1&amp;savelog=[log_file_name]&amp;cmd_var1=[argument]'&quot;, shell=True)
  </code></pre>
  <p>I started getting errors because of the &amp; characters in the URL parameters. Example:</p>
  <pre><code>'savelog' is not recognized as an internal or external command, operable program or batch file.
  'cmd_var1' is not recognized as an internal command or external command or operable program or batch file.
  ERROR: The string is missing the terminator: '.
  </code></pre>
  <p>If I surround the URL with double quotes, like:</p>
  <pre><code>subprocess.check_output(&quot;Powershell Start-Process -FilePath chrome -ArgumentList \&quot;'file://[path_to_automation_file]?direct=1&amp;savelog=[log_file_name]&amp;cmd_var1=[argument]'\&quot;&quot;, shell=True)
  </code></pre>
  <p>Google Chrome is launched successfully, but the URL is not passed to it i.e. I'm seeing the default home page. I've tried a few different options (encoded command, playing around with single and double quotes, etc.) but nothing worked.</p>
  <p>My preference is to keep the changes to the existing scripts minimal (anything I do for Windows should also have backwards compatibility with Mac). What can I do to get it working? Thanks in advance!</p>