DrDamnit
asked on
RedirectStandardOutput is not working
I have code the fires off a command line program to copy a file to a linux box from a Windows Server 2008 Enterprise box. The command line program is pscp.exe.
The code works, and pscp.exe is executed as the proper user, runs, then exists. Problem is, the file is not being uploaded. So I need to see what the output of pscp.exe is doing when being executed from within my program. (I suspect there is not something correct in the arguments passed and it is just giving me a message then quitting).
So, I try to redirect the standard output, which seems like it works as well, excpet when I try to write it to a log file, the log file is blank and zero bytes.
What did I do wrong? Why is there nothing in the log file that can tell me what's going on with pscp.exe when it fires?
For the points:
Correct my code so that the output of pscp.exe shows up in the temp.log file.
The code works, and pscp.exe is executed as the proper user, runs, then exists. Problem is, the file is not being uploaded. So I need to see what the output of pscp.exe is doing when being executed from within my program. (I suspect there is not something correct in the arguments passed and it is just giving me a message then quitting).
So, I try to redirect the standard output, which seems like it works as well, excpet when I try to write it to a log file, the log file is blank and zero bytes.
What did I do wrong? Why is there nothing in the log file that can tell me what's going on with pscp.exe when it fires?
For the points:
Correct my code so that the output of pscp.exe shows up in the temp.log file.
Dim password As SecureString = New SecureString
Dim strBuffer As String = ""
Dim x As Integer
Dim strPassword = "password1"
For x = 0 To Len(strPassword)
password.AppendChar(Mid(strPassword, x + 1, 1))
Next
Dim pi As ProcessStartInfo = New ProcessStartInfo
With pi
.Arguments = " -v -i myprivatedsakey.ppk c:\util\remote-tools.exe root@12.34.56.789:/tmp/remote-tools.exe"
.FileName = "C:\util\pscp.exe"
.Verb = "open"
.UserName = "Administrator"
.Domain = "MYDOMAIN"
.Password = password
.WorkingDirectory = "C:\Util\"
.UseShellExecute = False
.RedirectStandardOutput = True
End With
Dim p As Process = New Process
With p
.StartInfo = pi
.Start()
End With
Do Until p.StandardOutput.EndOfStream
strBuffer = strBuffer & p.StandardOutput.ReadLine
Loop
p.WaitForExit()
Dim streamOut As StreamWriter = New StreamWriter("C:\temp\temp.log")
streamOut.Write(strBuffer)
streamOut.Close()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.