PFBコード。私は出力を直接キャプチャしようとしましたが、運はありません。その後、出力をログファイルに入れて、後でログファイルからテキストを取得しようとしました。それもうまくいきませんでした。これで間違っていることを教えてください。以下は私はpowershellフォームからバッチファイルを実行しようとしており、表示用のテキストボックスにバッチファイルの出力をキャプチャしようとしています
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$Form = New-Object System.Windows.Forms.Form
$Form.width = 600
$Form.height = 600
$Form.Text = "Form Title"
$Form.startposition = "centerscreen"
$Form.FormBorderStyle= [System.Windows.Forms.FormBorderStyle]::Fixed3D
Function ShowProcess(){
$Textbox1 = New-Object System.Windows.Forms.RichTextBox
#$text = Get-Process | Out-String
$Textbox1.Size = New-Object System.Drawing.Size(550, 400)
$Textbox1.Multiline = $true
$Textbox1.Font ="Lucida Console"
$Textbox1.WordWrap = $false
Start-Transcript -Path C:\Mywork\log.txt
&C:\Mywork\Script\test.bat
Stop-Transcript
$Textbox1.Text = Get-Content C:\Mywork\log.txt
$Form.Controls.Add($Textbox1)
}
$button1 = New-Object System.Windows.Forms.Button
$button1.Location = New-Object System.Drawing.Point(350, 450)
$button1.Size = New-Object System.Drawing.Size(120, 100)
$button1.Text = "Press"
$button1.FlatAppearance.BorderSize=0
$Form.Controls.Add($button1)
$button1.Add_Click({ShowProcess})
$Form.ShowDialog()
test.bat
の内容です:
PS C:\Users\sghosh> Get-Content C:\Mywork\Script\test.bat tree pause
'起動プロセスを-ArgumentList CMD「/ C C:\ Mywork \ Script \ test.bat "'?オプションで '-RedirectStandardOutput'を投げてファイルに保存します。 – 4c74356b41