All code in a form must be run in an event. With a job you will need to use a timer to poll the job. The output of the job will need to be parsed to eliminate the elements of the received object to get only what you need.
See the following for an explanation of how jobs can be used in a form.
http://info.sapien.com/index.php/guis/g ... sive-forms
Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
I followed and studied the link you sent me.
But I can not figure out how to adapt it to my need could you write a short example for the textbox?
But I can not figure out how to adapt it to my need could you write a short example for the textbox?
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
There is no such thing as a short example of that code.
Add a job and a timer then set the timer tick to poll the job and add it to the textbox.
Don't try to build job tracker just use the post to learn how the JobTracker is designed and then use the components you need.
Add a job and a timer then set the timer tick to poll the job and add it to the textbox.
Don't try to build job tracker just use the post to learn how the JobTracker is designed and then use the components you need.
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
Here is the simplest example I can think of:
- $form1_Load={
- $timer1.Interval = 500
- $timer1.Start()
- }
- $buttonPingTracker_Click={
- $sb = { Get-Content d:\scripts\pinger.txt -Wait -Tail 1 }
- Start-Job -Name pinger -ScriptBlock $sb
- }
- $timer1_Tick={
- if($results = Receive-Job pinger -ErrorAction 0){
- $textbox1.Lines += $results
- $textbox1.Select($textbox1.Text.Length,1)
- $textbox1.ScrollToCaret()
- }
- }
- $form1_FormClosing=[System.Windows.Forms.FormClosingEventHandler]{
- Stop-Job pinger -ErrorAction 0
- Remove-Job pinger -ErrorAction 0
- }
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
I tryed with your code but i unable to show textbox content
- $Form1 = New-Object System.Windows.Forms.Form
- $Form1.Size = New-Object System.Drawing.Size(790,980)
- $Form1.FormBorderStyle = 'FixedDialog'
- $Form1.MaximizeBox = $false
- $Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + "\powershell.exe")
- $Form1.Icon = $Icon
- $Form1.Text = "Log View"
- ############################################## OutPutBox
- $textbox1 = New-Object System.Windows.Forms.TextBox
- $textbox1.Location = New-Object System.Drawing.Size(20,20)
- $textbox1.Size = New-Object System.Drawing.Size(680,900)
- $textbox1.MultiLine = $True
- $textbox1.ReadOnly = $True
- $textbox1.Font = New-Object System.Drawing.Font("Calibri",11,[System.drawing.FontStyle]::Bold)
- $textbox1.ForeColor = [Drawing.Color]::Green
- $textbox1.ScrollBars = "Vertical"
- $Form1.Controls.Add($textbox1)
- $form1_Load={
- $timer1.Interval = 500
- $timer1.Start()
- }
- $buttonPingTracker_Click={
- $sb = { Get-Content C:\script\PingLog.csv -Delimiter -Wait -Tail 1 }
- Start-Job -Name pinger -ScriptBlock $sb
- }
- $timer1_Tick={
- if($results = Receive-Job pinger -ErrorAction 0){
- $textbox1.Lines += $results
- $textbox1.Select($textbox1.Text.Length,1)
- $textbox1.ScrollToCaret()
- }
- }
- $form1_FormClosing=[System.Windows.Forms.FormClosingEventHandler]{
- Stop-Job pinger -ErrorAction 0
- Remove-Job pinger -ErrorAction 0
- }
- $Form1.Add_Shown({$Form1.Activate()})
- [void] $Form1.ShowDialog()
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
With this code i can able to read the content of file, but the content doesn't update
- $timer1 = new-object timers.timer
- #$form_Load={
- $timer1.Interval = 500
- $timer1.Start()
- #}
- $sb = { Get-Content c:\script\PingLog.csv -Wait -Tail 1 }
- Start-Job -Name pinger -ScriptBlock $sb
- #$timer1_Tick={
- if($results = Receive-Job pinger -ErrorAction 0){
- $outputBox.Lines += $results
- $outputBox.Select($outputBox.Text.Length,1)
- $outputBox.ScrollToCaret()
- }
- #}
- $form_FormClosing=[System.Windows.Forms.FormClosingEventHandler]{
- Stop-Job pinger -ErrorAction 0
- Remove-Job pinger -ErrorAction 0
- }
Re: Monitor A Text File From Windows PowerShell In Real Time with OutPut Text Box
Find the problem !
With the help of Powershell Studio !
Many thanks !
With the help of Powershell Studio !
Many thanks !