title: Pass input to CMD, using CMD process id (PID) in powershell
body: <p>Thanks to Abbas, the following code enable us to call a cmd process and pass command to it using PowerShell script.</p>
  
  <pre><code>$psi = New-Object System.Diagnostics.ProcessStartInfo;
  $psi.FileName = "cmd.exe"; #process file
  $psi.UseShellExecute = $false; #start the process from it's own executable file
  $psi.RedirectStandardInput = $true; #enable the process to read from standard input
  
  $p = [System.Diagnostics.Process]::Start($psi);
  
  Start-Sleep -s 2 #wait 2 seconds so that the process can be up and running
  
  $p.StandardInput.WriteLine("dir"); #StandardInput property of the Process is a .NET StreamWriter object
  </code></pre>
  
  <p>Now, How can I use a CMD process that already exists.</p>
  
  <p>In better words, I want to use the PID of a cmd.exe process that is running and pass the command to it.</p>