3

Is it possible to send text to the current prompt line? Something like the following:

PS[10]> Get-Location
c:/
PS[11]> Write-PromptLine "This text has been written by Powershell"
PS[12]> This text has been written by Powershell|
# | denotes the caret
0

1 Answer 1

5

You could use the SendKeys.SendWait method:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("This text has been written by Powershell")
Sign up to request clarification or add additional context in comments.

3 Comments

I was hoping the $host object would provide that functionality, but I'll try later whether your approach would work for me. Thanks.
I couldn't find anything in $host (that's the first thing I tried), but SendKeys does what you asked for. What are you trying to accomplish, exactly?
Send last cmd line to editor, block execution of shell, edit cmd in editor, save to temp file, close editor and send result to PS prompt line without executing straight away. Can't test right now, though. Your solution should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.