Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell execute external command in same window

Tags:

powershell

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?

like image 507
Raffaeu Avatar asked Feb 10 '14 12:02

Raffaeu


People also ask

Can PowerShell run commands in parallel?

Powershell workflows provide a powerful way to run powershell modules and scripts against multiple servers in parallel.

How do I run two commands simultaneously in PowerShell?

Using AND(&&) Operator You can use this in both CMD and Powershell. Usage: command1 && command2 && command3 [&& command4 ...]


1 Answers

Does this work for you?

$outcome = Invoke-Expression "cmd.exe /c dir"
$outcome
like image 165
arco444 Avatar answered Sep 24 '22 01:09

arco444