将dll文件在控制台输出的内容,写到文件中


前段时间想实现,将dll文件在控制台上输出的内容,写到文件中

试用了多种方法如:Start-Transcript、out-file等等,都不能实现我想要的功能,只能将脚本输出的内容写到文件中,经过前辈的努力找到了一种解决吧方法如下:

$returnCd	
Function forText(){	
    $startTime = Get-Date -Format 'yyyyMMddhhmmffff'	
    [System.Console]::Writeline("")	
    [System.Console]::Writeline("********** xxxxxxxxxx ***************")	
    [System.Console]::Writeline("")	
	
     xxxx.dll
}	
	
$path = "e:logfile.log"	
$outStream = New-Object IO.FileStream($path,'Append','Write','Read')	
$writer = new-object System.IO.StreamWriter $outStream	
[System.Console]::setout($writer)	
$returnCd = forText	
$writer.close()	
return $returnCd	

原理是将输出的内容,先写到流中,然后再写到文件中。

如果还有其他的好的方法请给我留言,先行谢过!!!

本文链接: https://www.pstips.net/redirect-dll-output-to-file.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注