Android Question jkSSH2 - SSH2 CmdExecuted help

emockler

Member
Licensed User
Longtime User
I am sending a command to a server over ssh. The command may succeed or fail at the server.
I want to test for this, and on failure send a different command that will succeed.

So I grabbed this piece from the library example:

Sub SSH_CmdExecuted (Success As Boolean, Result AsList, TaskId As Int)
Log (TaskId)
If Success Then
For i=0To Result.Size-1
Log(Result.Get(i) & CRLF)
Next
EndIf

SSH2.close
End Sub


I inserted a "do something" in the "If Success" section (even just a msgbox for testing).
When the command is successful at the server, I get the msgbox as expected.
If the command fails I get no msgbox.

I want to do one thing upon success, something else upon failure.

I can't seem to use:

if not success

if success = 0

if success then
do something
else
do other thing
end if

Sub SSH_CmdExecuted (Success As Boolean, Failure as boolean, Result AsList, TaskId As Int)

The task I put after "If Success Then" works and seems to be dependent on the remote command's success. But I am not getting anything to happen in the CmdExecuted sub upon failure.


I intersperse msgboxes through this sub, and they show the sub is run either way. But I can't get anything to happen upon failure.

like this:
Sub SSH_CmdExecuted (Success As Boolean, Result AsList, TaskId As Int)
Log (TaskId)
Msgbox( "executed" ,2) <----this always displays
If Success Then
For i=0To Result.Size-1
Msgbox( Result.Get(i),1) <------ this displays when successful, with txt from server even.
Log(Result.Get(i) & CRLF)
Next
EndIf

SSH2.close
End Sub

Thanks for any insight into this!
Eric


PS: Stupid firefox won't let me insert code, I'm not ignoring the "how to post" etiquette.
 

emockler

Member
Licensed User
Longtime User
I guess I fixed it enough for my purposes......

I am sending a command to shutdown a vm
If vmware tools are installed, I can do "power.shutdown"
If not, I have to do "power.off"

so I sent get.guest which returns tools status, among many other things

Then Result.get(7) -> string

then test the string & send appropriate command.

I would have liked to test for the "can't do that" when sending power.shutdown, but I guess it's better in the long run since I learned how to get specifics beyond success or failure from the server.

In case anyone's interested:

Under a button click:
SSH2.execCommand("vim-cmd vmsvc/get.guest 98", 11)


Sub SSH_CmdExecuted (Success As Boolean, Result As List, TaskId As Int)
'Msgbox( "executed" ,2)
Dim tools As String
Log (TaskId)
If TaskId = 11 Then
If Success Then
Msgbox( Result.Get(7),1)
tools=Result.Get(7)
End If

If tools.Contains("NotRunning") Then
SSH2.execCommand("vim-cmd vmsvc/power.off 98", 15)
Else
SSH2.execCommand("vim-cmd vmsvc/power.shutdown 98", 15)
End If

End If
End Sub
 
Upvote 0
Top