darkoperator / darkoperator/Posh-SSH
New-SSHShellStream: how to figure out when a command has finished executing?
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 222
- PR merge metrics
- No merged PRs in 30d
Description
$stream = New-SSHShellStream -SSHSession $ssh
$stream.writeline("someLongRunningCommand")
$stream.read()
I have a simple script that calls a long running script such as ansible playbook that takes a long time to run and outputs different tasks until it's done. How can I tell when the command has finished running? I see the $stream contains properties CanRead, DataAvailable, and CanWrite. CanRead and CanWrite is always True throughout the script running. DataAvailable changes from false to true as data is available to read so then I can call $stream.read() to get the data. So I want to write a loop that can output any data available as the script is running and sleep 1 second between checking for DataAvailable before outputting the data. But I don't know when to break the loop since I don't know when the script has finished executing. I could check the data for the ending line of the script, but if an error occurs in the script and never outputs the expected last line then I'll be stuck in a loop. Any ideas?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the New-SSHShellStream entry point and the stream properties named in the report: CanRead, DataAvailable, and CanWrite. Investigate how command completion or remote-session errors are exposed for long-running commands, then define a reliable completion signal and verify it with a long-running command that succeeds and one that fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100