The main reason you get zero output from a command such as dir
is because dir
doesn't exist. It's part of the command prompt, and the solution to this particular problem is well, in this page somewhere.
You can find this out by pressing WIN + R
, and typing in dir
or start
for that matter - an error message appears!
However perverse this may sound, I've found that the most reliable way to do anything process related in Windows is with using the Component Object Model. You said for us to share our experiences, right?
$me hears people laughing
Regained your composure yet?
So, first we'll create the COM object:
$pCOM = new COM("WScript.Shell");
Then, we'll just run what ever needs to be run.
$pShell = $pCom->Exec("C:\Random Folder\Whatever.exe");
Cool! Now, that'll hang until everything's finished in that binary. So, what we need to do now is grab the output.
$sStdOut = $pShell->StdOut->ReadAll; # Standard output
$sStdErr = $pShell->StdErr->ReadAll; # Error
There's some other things you can do - find out what was the process ID, error code, etc. Although this example is for Visual Basic, it's based on the same scheme.