Avatar of DrDamnit
DrDamnitFlag for United States of America 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.
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")

Open in new window

.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.