Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

RedirectStandardOutput is not working

Avatar of DrDamnit
DrDamnitFlag for United States of America asked on
.NET ProgrammingVisual Basic.NET
1 Comment1 Solution805 ViewsLast Modified:
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.
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))
            Dim pi As ProcessStartInfo = New ProcessStartInfo
            With pi
                .Arguments = " -v -i myprivatedsakey.ppk c:\util\remote-tools.exe root@"
                .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
            End With
            Do Until p.StandardOutput.EndOfStream
                strBuffer = strBuffer & p.StandardOutput.ReadLine
            Dim streamOut As StreamWriter = New StreamWriter("C:\temp\temp.log")
Avatar of miahi
miahiFlag of Romania image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers