"tomaszinc" <tomaszinc@xxxxxx> wrote in message
news:B7AEAF9C-B5F0-4204-8A27-6CC86554338D@xxxxxx
Quote:
> Thanks a lot for your quick answer.
>
> The page is great, but if I don't get it wrong then what he says is: "you
> can't capture console output".
Not quite. "Output" is an interesting term in PowerShell. In PowerShell,
output consists of what you would find in stdout in other shells with the
exception being that the type of the output may be a string (a .NET object)
or it may be any other type of .NET object. In PowerShell, there are times
that you want to communicate something to the console user but not have that
communication (a string) get mixed up with the stdout output. In this case,
you would use a cmdlet like Write-Host. For instance, given this function:
function foo {
"Hi"
$true
1
[Math]::Pi
Write-Host "In function foo"
}
$result = foo
The $result variable in this case would contain the stdout of the function
foo (string hi, boolean True, int 1 and double 3.14159...). However the
output would not contain the string "In function foo" because that message
is written directly to the host/console. My point was that if you are
wanting to log everything output by a script, you can't capture these
messages written directly to the console/host unless you use
Start-Transcript.
Quote:
> I now tried different combinations of |out-string -stream | out-file
> -encoding {oem, default} and so on. I actually managed to capture some
> command line output correctly, but python script output still is totally
> messed up. So what works for one is no solution for another.
>
> I'm sorry, but this is just garbage. I mean, a shell where you can't even
> redirect console output to a file is totally worthless, no matter how
> fancy
> the output is presented on screen or what other cool features it offers.
Just so you know you can redirect stdout/stderr output to a file. The team
made the decision to be "forward thinking" and default the redirection
output encoding to Unicode. Perhaps at some point, in retrospect, that will
appear to be a brilliant decision but for the moment it can be problematic
until you know it does that and you know how to get around it (using
Out-File -enc ascii).
For what it's worth, I feel your pain. Getting started with PowerShell can
be frustrating especially if you have *lots* of experience with other
shells. PowerShell requires a while to make the transition from the
text-based processing approach to the object-based processing approach.
There are a number of subtleties. And I'm not saying that you still don't
need text processing. You do and that is an area where PowerShell is just a
bit weak IMO.
Quote:
> I guess I just stick with cygwin shell scripting, at least MS is not
> messing
> up my data here. It's a pity though, powershell promises so much and then
> even the most simple and basic tasks are impossible to do.
Give it a bit more time and feel free to ask questions on this newsgroup.
You might also want to check out my entire Effective PowerShell series. It
really helps to have a good mental model for how PowerShell works. I also
recommend "Windows PowerShell in Action" to help you climb the learning
curve. But if you're not ready to commit that much to PowerShell yet, just
keep the questions coming here. There are a lot of folks here willing to
help you out.
--
Keith