Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This forum is a space to discuss coding involving Graphical User Interfaces (GUI) in PowerShell or using WinForms controls, and technical issues related to development.
I have written a script that has a GUI for interaction, but the desire to interact with it via command line has come up and I have implemented some basics of being able to run actions (functions) from the GUI silently without the GUI loading obviously, but is there a way to redirect the output to the Powershell window that called it? I know the purpose is to redirect all output to the GUI forms, but I also saw in the startup.pss :
.SYNOPSIS
The Main function starts the project application.
.PARAMETER Commandline
$Commandline contains the complete argument string passed to the script packager executable.
.NOTES
Use this function to initialize your script and to call GUI forms.
.NOTES
To get the console output in the Packager (Forms Engine) use:
$ConsoleOutput (Type: System.Collections.ArrayList)
Is there a way to achieve what I am asking? I did try tinkering with the above, but I was unsuccessful.
I don't know about returning output to a console from a project packaged with the Windows Forms engine, but I did a project for work where I wanted to provide the same tool through a GUI application as well as from the command line. What I did was this:
1) I included in the project a powershell wrapper script to call the cli version of the tool. This gives the users the added convenience of parameter name tab completion, etc.
2) Set the wrapper script Build property to Exclude so it's not included when you build the project
3) Built the project twice - once with the Windows Forms script host, and once with the Command line script host (adding 'cli' to the end of the output file)
4) Finally, for the installer, include both of your packaged executables (the windows forms and the command line exe's) as well as the powershell wrapper script for the cli version.
One other note - I added an If ($sapienhost.gettype().module.scopename -like "PoshExeHostCmd*") statement in the project code (in startup.pss) so it can detect if it is running using the command line or the windows forms script host so I could make it behave appropriately in either case.
I know this isn't the specific answer you're looking for, but it works out great for my project.