8000 GitHub - quonic/Expect: Spawn, Expect, and Send, but for PowerShell in pure PowerShell!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ Expect Public

Spawn, Expect, and Send, but for PowerShell in pure PowerShell!

License

Notifications You must be signed in to change notification settings

quonic/Expect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expect

Spawn, Expect, and Send, but for PowerShell in pure PowerShell!

How to use

Just like how you would use spawn, expect, and send Import the module, include in your profile, or add it to your script.

Spawn or Invoke-Spawn will spawn a pwsh or powershell process and run the command you give it. Calling Invoke-Spawn a second time will recreate the process, stopping the previous process.

Expect or Wait-Expect will wait for a specific output. Either Regex or a simple match. Regex it tried first.

Send or Send-String will send a string response to the process.

Close or Close-Spawn when you wish to close the process for clean up or to start a new Invoke-Spawn process.

Examples

Simple match:

Spawn -Command '$a = Read-Host -Prompt "Test Response"' # Spawn a powershell or pwsh process with a command
Expect -SimpleMatch "Test Response*" -Timeout 2 # Expect a response
Send -Command "My Response" # Send the response
Close # Close the spawned process if it still runs

Regex match:

Spawn -Command '$a = Read-Host -Prompt "Test[Response]"' # Spawn a powershell or pwsh process with a command
Expect -Regex "Test\[Response\].*" -Timeout 2 # Expect a response
Send -Command "My Response" # Send the response
Close # Close the spawned process if it still runs

Install

As a module

Install-Module -Name Expect

or for your current user

Install-Module -Name Expect -Scope CurrentUser

Include in your profile or script

Download or copy the Expect.ps1 from the root of this repository and add it to your Profile.ps1 or script.

Contributions

Code or Issue contributions are welcome!

About

Spawn, Expect, and Send, but for PowerShell in pure PowerShell!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0