I am trying to execute an external command using powershell, without having the second program to popup, I need to execute this program within the same PowerShell window and output both the log and the errors. I started with this:
$outcome = Start-Process -Wait -FilePath "cmd.exe" -ArgumentList "dir" -NoNewWindow 2>&1
$outcome
But it doesn't work as expected. I still see the new window popping up with DOS and no redirect at all about the output, the errors and so on. Am I doing something wrong?
Invoke-Expressioninstead?Invoke-Expression "$PWD\.venv\Scripts\Activate.ps1"worked for me in my use case.