Write-Output not functional

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
harv
Posts: 2
Last visit: Fri May 01, 2009 12:40 am

Write-Output not functional

Post by harv »

Hi,

I'm obviously missing something because Write-Output is not working in the code I plug into the ButtonName_OnClick{} code in the .PS1 generated out of Primal Forms. If I change it to Write-Host or Write-Warning those produce output to the console, but I want to be able to redirect the script's output to a file, viz: .test1.ps1 >saved.txt

Here's the simplest case I could create. It's a blank form with a single button. When the button's pressed the _OnClick{} just does a Write-Output with canned message. The message disappears into the bit bucket.

TIA for showing me the right way.

Harv

#Generated Form Functionfunction GenerateForm {######################################################################### Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0# Generated On: 04/29/2009 1:29 PM CDT# Generated By: Harv.Stewart########################################################################
#region Import the Assemblies[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null#endregion
#region Generated Form Objects$form1 = New-Object System.Windows.Forms.Form$button1 = New-Object System.Windows.Forms.Button$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState#endregion Generated Form Objects
#----------------------------------------------#Generated Event Script Blocks#----------------------------------------------#Provide Custom Code for events specified in PrimalForms.$button1_OnClick= {#TODO: Place custom script hereWrite-Output "You pressed the button!"
}
$OnLoadForm_StateCorrection={#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState}
#----------------------------------------------#region Generated Form Code$form1.Text = 'Test Write-Output'$form1.Name = 'form1'$form1.DataBindings.DefaultDataSourceUpdateMode = 0$System_Drawing_Size = New-Object System.Drawing.Size$System_Drawing_Size.Width = 519$System_Drawing_Size.Height = 114$form1.ClientSize = $System_Drawing_Size
$button1.TabIndex = 0$button1.Name = 'button1'$System_Drawing_Size = New-Object System.Drawing.Size$System_Drawing_Size.Width = 191$System_Drawing_Size.Height = 53$button1.Size = $System_Drawing_Size$button1.UseVisualStyleBackColor = $True
$button1.Text = 'Push Me!'$button1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",16,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point$System_Drawing_Point.X = 70$System_Drawing_Point.Y = 24$button1.Location = $System_Drawing_Point$button1.DataBindings.DefaultDataSourceUpdateMode = 0$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
#endregion Generated Form Code
#Save the initial state of the form$InitialFormWindowState = $form1.WindowState#Init the OnLoad event to correct the initial state of the form$form1.add_Load($OnLoadForm_StateCorrection)#Show the Form$form1.ShowDialog()| Out-Null
} #End Function
#Call the FunctionGenerateForm
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Write-Output not functional

Post by jhicks »

A Windows form blocks until it completes. I don't think you'll be able to direct the script output because it really doesn't have any. What you can do is create the file within your script.write-output "You pressed the button!" | Out-File c:tempfoo.txtThat's the way I would do it.
User avatar
harv
Posts: 2
Last visit: Fri May 01, 2009 12:40 am

Write-Output not functional

Post by harv »

jhicks,

Thanks for the info. Actually the form does produce output, since if you change the Write-Output to Write-Host or Write-Warning the message appears at the PS console.

Meanwhile I hit on your solution to use Out-File with the -Append option to capture multi-line output to a file. The form was changed so that rather than offer the user a checkbox for CSV output there is now a textbox for entering the [path]filename.ext where they want it put. If the textbox is empty that means no output is desired.

I'm an expert using .CMD, .VBS and .AWK scripts but am pretty new to PowerShell and Windows Forms. Thanks again for your help!

Harv
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Write-Output not functional

Post by jhicks »

I should have been specific - not pipeline output. Although it probably should work. Still, I think creating the file within the script is a better way to go.
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.