Get the string result from Execute() during the execution

Apr 14, 2013 at 2:30 PM
Hi all
I am using SshCommand object and running an SSH file on a Linux machine using the Execute() function as follow

SshCommand command = client.CreateCommand(string.Format("{0} {1}", shPath, cmdPath));
command.CommandTimeout = new TimeSpan(24, 0, 0);
string commandResult = command.Execute();
StreamWriter sw = new StreamWriter(logFilePath);
sw.WriteLine(commandResult);
sw.Close();

I want to display the result string (as an execution's log) and sometimes the execution takes several minutes while in this time I can't display anything.

I want to display the result during the execution so the end user will see the progress.
so what I need is an option to get the string result during the execution.
Can anyone help me how can i do it?
Apr 10, 2014 at 2:05 AM
Why has there been no response to this question? It would be very usefull to be progressively notified about received string data as the response is read from server by the ssh.net library. For example line by line from an event property on the SshCommand class. Can anyone give feedback on this? Is it possible today?
Apr 10, 2014 at 6:14 AM
awaitbytes wrote:
Why has there been no response to this question?
You know the devs do it in their freetime? And they give to you for free! Insane, right?
You have a private life too, aye? Sometimes it can happen questions get forgotten, no reason to ask such a rude question!
I try to answer a lot of questions, but it's also my freetime! And I do it since I like this project and want to help the devs.
You should try it, too! Helping is nice :)

Beside this is a well documented feature in the docs. You always should read the docs and ask questions then.
Else you look like a lazy person.
It would be very usefull to be progressively notified about received string data as the response is read from server by the ssh.net library. For example line by line from an event property on the SshCommand class. Can anyone give feedback on this? Is it possible today?
SshCommand can be used Async with BeginExecute, callback and EndExecute.
It is well documented in the docs.

Note: The main page also mentions "Execution of SSH command using both synchronous and asynchronous methods".
Do your homework before asking rude questions.
Apr 10, 2014 at 1:50 PM
BAM!

Nailed it!
Apr 11, 2014 at 12:06 AM
Well first of all I have to say I have used this library for a couple of projects and I like it! And really do appreciate the work all developers have done. So hats off to them :)

And secondly, I didn't intend to be rude, I was more baffled to be honest in reference to my opening.

I must say, it's very ironic of you to call me lazy. Because a) I wasn't lazy. b) You didn't fully comprehend my question. So you violated your own rule there, read/comprehend before you rant;)

I am very well aware of the Begin/EndExecute. However it does not address the question of polling or being notified on how the SshCommand is progressing during it's execution.
I am also aware of SshCommand.OutputStream. However, I am not very sure about consequences of read/write in terms of unwanted side effects/bugs of reading the stream while BeginExecute write. One side effect seem to be that the result is empty on EndExecute. And reading the OutputStream on another thread is totally out of the question and not thread safe. I even tried it for good measure.
So that was my issue. Which I could not find a good example of or answer to. Instead of assuming, I wanted to ask. It seems I am able to solve my case, but Imho it would be nice to have a way to plug into SshCommands progress that is conspicuous to any developer using ssh.net and effective in terms of resources and implementation. And which the developer can have full confidence in using, in a multi-threaded world. If there is a way, I haven't seen it yet.

Also, to be exact, you got APM and Async mixed up.. they solve the same problem, but they are distinct paradigms in the world of .net. The Begin/End methods you are referencing follow the APM paradigm, not Async. Do your homework! ;) As you so eloquently said.

And finally, keep in mind, we're on the same team :)
You know the devs do it in their freetime? And they give to you for free! Insane, right?
You have a private life too, aye? Sometimes it can happen questions get forgotten, no reason to ask such a rude question!
I try to answer a lot of questions, but it's also my freetime! And I do it since I like this project and want to help the devs.
You should try it, too! Helping is nice :)

Beside this is a well documented feature in the docs. You always should read the docs and ask questions then.
Else you look like a lazy person.
Apr 11, 2014 at 4:04 AM
"Why has there been no response to this question? ... Can anyone give feedback on this? Is it possible today?"

"And secondly, I didn't intend to be rude, I was more baffled to be honest in reference to my opening."
__
<$0.02>

You seem confused. This might help:
  1. Act on a public forum as if you are talking to your [almost] deaf Grandmother. Don't be upset, or imply demands, or ask why she hasn't answered your question. Be instead polite & respectful, but not condescending. She may ask you to repeat, or ask the question a different way, but she still means well. She's old & sensitive, really does want to help, but still not stupid.
  2. What you write should be taken as polite & considerate even when shouted. If I was to shout to a group of people I didn't know "Why has there been no response to this question?", who would be surprised if they snubbed me?
  3. If there is any chance, however remote, of your post being taken as rude, or the opposite of what you intended, by native or non-native speakers, it will be. Assume that.
  4. How you write paints a picture of who you are-it's all we can go by, after all! So you might be the nicest person in the world, but all the public has to go by is what you write, and how you write it. If you are a swell person, and a horrible communicator, you won't make the impression you think you're giving. Just be tolerant of the communications vehicle you are using, and how little we all have to go by.
  5. If you can't work with this program/suite alone, then you just need to be able to communicate your needs professionally & respectfully. The forum has already given you direct feedback on what isn't working, so consider it advice and move forward.
Giving respect, and not demanding it, will get you the world.

</$0.02>

Best,
pat
:)
Apr 11, 2014 at 7:06 AM
Edited Apr 11, 2014 at 12:31 PM
Thanks to BogusException to explain Internet Communications 101.
It should make you think that two people seemed to read your post as rude and unfriendly.

Btw. don't make fun of non-native speakers on the internet. Thats even more rude than your first post.
So I won't help you. But maybe you are lucky and someone else will.

Oh, we are totally not on the same team. It's your first time posting here, I don't know you and currently
I don't think it's worth the effort.

And since you are such a smart guy, when we talk about async (a valid short term for asynchronous) and this library
"is complete rewrite using .NET 4.0" (source https://sshnet.codeplex.com/) guess which async I mean?
May 1, 2014 at 8:51 AM
<response to non-technical bullshit>
You cut and snip my words out of context to make your argument? And patronize under the false pretence of giving "advice".. Really? And you talk about being polite and considerate? You are in no position to lecture anyone on forum etiquette.. ever. And you are certainly not in a position to be patronizing.. One word comes to mind: pathetic.

And your two cents are worth zero to me, or anyone reading this forum to get answers or understand ssh.net for that matter.

And dont worry... I would find better technical advice in google translating a drunk russian hobo ramblings than you guys (or the one person hiding behind two pseudonyms). So thanks, but no thanks..

Mixing up technical terms is just the tip of the iceberg in what is your total lack of insight.. And that explains why you get so defensive right off the bat, protecting your ego because of your insecurities.

I don't make fun of non-native speakers, I am one myself.. But I do make fun of people trying to be smarter than they are.
We are on the same team.. just in different leagues;) But you just dont get it..

And yes.. my late response really is a measure of how little I regard you and your "input".
</response to non-technical bullshit>

To anyone interested in the OP question. You cannot/should not read the response stream before the command has completed. However it wouldn't be too difficult to implement the option to read the response concurrently in a thread safe manner if you need it. I did not as it was a nice to have feature, and not need to have.
May 1, 2014 at 10:08 AM
Aye, let's get back to topic. Sorry we got your writings wrong. But you must accept you are quite offensive too, not to say quite lordly ;)

I'm not sure I get your statement right. Why shouldn't/can't you read from the response stream during execution?
I actually do it for "downloading" files with cat and/or custom shell-extensions.
May 1, 2014 at 9:20 PM
"And dont worry... I would find better technical advice in google translating a drunk russian hobo ramblings than you guys (or the one person hiding behind two pseudonyms).

So thanks, but no thanks.. "

I'm sure nobody here will have any difficulty complying with your wish.