일부 System.Diagnostics.Process
및 System.Diagnostics.ProcessStartInfo
클래스를 사용하는 powershell 스크립트를 만듭니다. PowerShell의 일부 .NET 4.0 클래스가 작동하지 않는 것 같습니다.
이 클래스
은 다음과 같이 완벽하게 잘 작동 :$stream = new-object System.IO.StreamReader
:
$processInfo = new-object System.Diagnostics.ProcessStartInfo
$processInfo.FileName = "dism.exe"
$processInfo.UseShellExecute = $false
$processInfo.RedirectStandardOutput = $true
$processInfo.Arguments = "/Apply-Image /ImageFile:C:\images\Win864_SL-IN-837.wim /ApplyDir:D:\ /Index:1"
$process = new-object System.Diagnostics.Process
$process.StartInfo = $processInfo
그러나, 나는 또한 System.IO.StreamReader 클래스를 사용하고 싶지만 나는 같은과 똑같은 일을하려고 할 때
또는이
$stream = new-object System.IO.StreamReader $process.FileName
처럼 오류를 얻을 :
New-Object : Constructor not found. Cannot find an appropriate constructor for type System.IO.StreamReader.
At C:\Users\a-mahint\Documents\Testing\inter.ps1:17 char:21
+ $stream = new-object <<<< System.IO.StreamReader
+ CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
저는 30 분 동안 이것을 알아 내려고 노력하고 있습니다 ... 어떻게 된 일입니까? 두 클래스 모두 .NET 4.0의 일부입니다.
감사합니다. 나는 내일 그 일을 시도 할 것입니다. –
사실 저는 미안합니다. 저는'$ process.StandardOutput'을 StreamReader 유형이고 Stream 유형을 허용하는 생성자에 전달했다고 말하고자합니다. 그럼 여전히 작동하지 않습니까? 아니면 그냥 명시 적으로 캐스팅 할 수 있습니까? –
StreamReader가 Stream에서 파생되지 않습니다. http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx – TrueWill