PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example for the SSHRead function
Example for the SSHRead function
This example is used to read the result of an SSH command.
// The session was started by SSHConnectShell
// cMySession is sshSession

let SSH_PROMPT = "$ "
let NB_ATTEMPTS  = 20
let MAX_ATTEMPTS = 2

nNbAttempts is int
nMaxNbAttempts is int
sStdOut is ANSI string
sStdOutline is ANSI string
sStdBuffer is ANSI string

// Read the console of SSH shell after sending a command
// with SSHWrite
WHILE True

// Consumes the content of the console by leaving 1s rest
sStdBuffer = SSHRead(cMySession, 1000, sshStandardOutput)

// As long as the console is empty
IF sStdBuffer = "" THEN

nNbAttempts = 0

// Try to read again until <NB_ATTEMPTS> times by leaving 100ms rest
// between each attempt
WHILE sStdBuffer = "" _AND_ nNbAttempts < NB_ATTEMPTS
nNbAttempts ++
sStdBuffer = SSHRead(oSession, 100, nConsole)
END

// End
IF nNbAttempts = NB_ATTEMPTS THEN

// Interactive mode (the shell expects an answer)
IF sStdOutline =]~ ":" THEN
BREAK
END

nMaxNbAttempts ++
nNbAttempts = 0

IF nMaxNbAttempts = NB_ATTEMPTS THEN
ErrorThrow(500, "Connection expired")
BREAK
END

CONTINUE
END
END

// If the console is not empty
IF sStdBuffer <> "" THEN

// Deletes the <CR> only
sStdBuffer = Replace(sStdBuffer, " " + Charact(13), "")

// Fills
sStdOutline += sStdBuffer

// If the line ends by <CR>
IF sStdOutline =] CR THEN

// Fills the output
sStdOut += sStdOutline
sStdOutline = ""

// Ccontinue to read
CONTINUE

// If the line ends by prompt
ELSE IF sStdOutline =] SSH_PROMPT

// Fills the output
sStdOut += sStdOutline
sStdOutline = ""

// End of reading
BREAK
ELSE

// Continue
CONTINUE
END
END
END

// Reminder
IF sStdOutline <> "" THEN

// Fills the output
sStdOut += sStdOutline
sStdOutline = ""
END
Minimum version required
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment