I have some helper functions that write to STDOUT for logging purposes. Some of these functions return a value to the caller, but the entire output from the function is returned.
How can I have my functions write to STDOUT and return a value to the caller without the return value being polluted with all the STDOUT emitted during the function call?
I'm looking for some kind of design pattern or best practise.
Consider this script:
Function a
{
Write-Output "In Function a"
$a = 4
return $a
}
$b = a
Write-Output "Outside function: `$b is $b"
The output is
Outside function: $b is In Function a 4
But I want the output to be:
In Function a
$b is 4
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…