-
-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot get streaming stdout/stderr and wait for remote process to exit #164
Comments
We've started working on this as part of PR #144, but I got sidetracked by some other issues. I'll soon reboot my work on this. |
Oh perfect! I'll keep an eye on that PR. If you want to close this immediately feel free, otherwise we can close this when PR #144 is ready :) |
You could also execute the command with extra " 2>&1" so the stderr is also routed to stdout and is readable in the cmd.Result. |
My scenario is that I want to start a process on a remote machine and wait for it to either crash, or exit gracefully. While I am waiting for it to crash/exit I want to propagate it's stdout/stderr to the host machine so I can parse it, or redirect it to file once I get the data I need from it.
My attempt is: https://gist.github.com/alanmcgovern/c12867f3accc6cf5870d5212d3425974#file-test-cs-L8
The issue with this approach is that the very first
(line = reader.ReadLine ())
returns null if you do it 'too quickly'. PipeStream thinks the stream has completed even though the process is still running on the remote machine. If i put a Thread.Sleep before that line I can read some output before i get a null, but eventually i get a null when reading, even though the process hasn't exited.The only 'reliable' approach to detect when my process exits is to create a ShellStream, then write this command:
path/to/long_lived_application; echo TOMBSTONE;
and then exit my read-loop when i see the stringTOMBSTONE
appear in the output.This approach is here: https://gist.github.com/alanmcgovern/c7bf0fab9760cfcd324573df51c98fbb
Is there a better way to asynchronously run a command and gather it's stdout/stderr?
The text was updated successfully, but these errors were encountered: