I am trying vba code to open cmd and do some stuff and after i get the result .
This is for the automate the process to connect to server and request a query and get result to store in excel sheet.
Sub hello()
Dim oShell As Object
Set oShell = CreateObject("Shell.Application")
Dim oOutput As Object
Dim oExec As Object
oShell.ShellExecute "cmd.exe"
Application.Wait (Now + TimeValue("0:00:05"))
SendKeys "plink.exe -ssh username@ipaddress -pw password"
Application.Wait (Now + TimeValue("0:00:05"))
SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("0:00:05"))
SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("0:01:00"))
SendKeys "run sql select n.dnorpattern as Directory_Number, n.description as "
Application.Wait (Now + TimeValue("0:00:05"))
SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("0:00:20"))
Application.Wait (Now + TimeValue("0:00:20"))
SendKeys "%{F4}", True
'handle the results as they are written to and read from the StdOut object
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then MsgBox sLine
Wend
I am trying this code to get output but failed
Set oOutput = oShell.StdOut
Any suggestions? Thanks