title: execute python with arguments
body: <p>I am trying to invoke a Python script that accepts arguments to backup a PostgreSQL database in VMware.</p>
  
  <p>Code is like this:</p>
  
  
  
  <pre class="lang-bsh prettyprint-override"><code># path to where you want to save the backup to
  $filepath = "D:\pgbackups\"
  
  # filename you want to call the backup
  $filename = "torwpinf002_postgresdb_bk_"
  
  # format the date/time so you can append to the backup filename
  $filedate = get-date -Format "yyyyMMdd_HHmm"
  
  # pack it all together 
  $fullFileSave = $filepath + $filename + $filedate.ToString() + ".bak"
  
  $BackupScriptFile = "C:\backup_win.py"
  
  $executebackup = "`"$BackupScriptFile`"" + ' -p  "QX+qos5eu1D36&amp;kB" -f ' + "`"$fullFileSave`""
  
  python $executebackup
  </code></pre>
  
  <p>If I throw a breakpoint I can display the variable <code>$executebackup</code> and it will show this:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>"C:\backup_win.py " -p  "QX+qos5eu1D36&amp;kB" -f "D:\pgbackups\torwpinf002_postgresdb_bk_20160715_1050.bak"
  </code></pre>
  
  <p>This throws the error:</p>
  
  <pre>python : usage: backup_win.py [-h] -p PASSWORD -f BACKUP_FILE
  At C:\Program Files\VMware\vCenter Server\python\torwpinf002_pgbackup.ps1:39 char:1
  + python $executebackup
  + ~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (usage: backup_w... -f BACKUP_FILE:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
  
  backup_win.py: error: argument -p is required</pre>
  
  <p>What is funny about this is, the box I am running this one is Windows 2012 R2. This SAME script works perfect on a Windows 2008 R2.</p>
  
  <p>Huh?</p>
  
  <p>Well, so I think what is happening is the double quotes on the command I am passing into the <code>python.exe</code> is mucking up the works, so I changed it a bit:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$executebackup = $BackupScriptFile + ' -p  "QX+qos5eu1D36&amp;kB" -f ' + $fullFileSave
  </code></pre>
  
  <p>resulting in the output of this if I echo it to the screen (notice no quotes around the file paths):</p>
  
  <pre class="lang-bsh prettyprint-override"><code>C:\backup_win.py  -p  "QX+qos5eu1D36&amp;kB" -f D:\pgbackups\torwpinf002_postgresdb_bk_20160715_1050.bak
  </code></pre>
  
  <p>but that returns this error:</p>
  
  <pre>python.exe : C:\Program Files\VMware\vCenter Server\python\python.exe: can't open file 'C:\backup_win.py  -p  QX+qos5eu1D36&kB -f 
  D:\pgbackups\torwpinf002_postgresdb_bk_20160715_1050': [Errno 22] Invalid argument
  At line:1 char:1
  + python.exe $executebackup
  + ~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (C:\Program File...nvalid argument:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError</pre>
  
  <p>I am really stuck, I am sure it is something simple that the experts can adjust in 5 seconds.. my brain is cooked and I am not sure what to try next. The part that bugs me the most is that it works fine on a Windows 2008 but not on 2012.</p>
  
  <p>Here is something really funny. If I take the output of the <code>$executebackup</code>:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>C:\backup_win.py  -p  "QX+qos5eu1D36&amp;kB" -f D:\pgbackups\torwpinf002_postgresdb_bk_20160715_1058.bak
  </code></pre>
  
  <p>and paste it into the PowerShell console it works just fine. </p>
  
  <pre>PS C:\Users\Administrator> <b>C:\backup_win.py  -p  "QX+qos5eu1D36&kB" -f D:\pgbackups\torwpinf002_postgresdb_bk_20160715_1058.bak</b>
  
  Backup completed successfully.</pre>
  
  <p>Any thoughts on how to get this to execute from within the script?</p>