Powershell Wrapper To Direct Piped Input To Python Script
I'm trying to write a little tool that will let me pipe command output to the clipboard. I've read through multiple answers on Stack Overflow, but they didn't work for me, because
Solution 1:
First, in PowerShell, a multi-line text is an array, so you need a [String[]]
parameter. To solve your problem, try using the process block:
function Out-ClipBoard() {
Param(
[Parameter(ValueFromPipeline=$true)]
[String[]] $Text
)
Begin
{
#Runs once to initialize functionpushdcd \My\Profile\PythonScripts
$output = @()
}
Process
{
#Saves input from pipeline.#Runs multiple times if pipelined or 1 time if sent with parameter$output += $Text
}
End
{
#Turns array into single string and pipes. Only runs once$output -join"`r`n" | python copyToClipboard.py
popd
}
}
I don't have Python here myself, so I can't test it. When you need to pass multiple items (an array) through the pipeline, you need the process block for PowerShell to handle it. More about process block and advanced functions is at TechNet.
Post a Comment for "Powershell Wrapper To Direct Piped Input To Python Script"