Question myProcess.StandardOutput.ReadToEnd Not Working

wright1968

Member
Joined
Feb 20, 2009
Messages
5
Location
Saint Joseph, IL
Programming Experience
1-3
Ok... this is driving me nuts.

I have the following code that works perfectly to disable an account in active directory using DSMOD in an application. But in another application, the exact same code results in failure. I'm absolutely confused as to why it works in App A and not in App B.

I've done tons of troubleshooting, and have even tried removing all the string references and replacing them with the actual text to make sure nothing weird is being passed to the arguments.

I have similar code for DSQUERY.EXE in the same app that returns results perfectly, but this block of code for DSMOD.EXE and another for DSRM.EXE doesn't seem to run correctly.

Here is the code in question

VB.NET:
     Dim myProcess As New Process
        Dim sReturnData As String = Nothing
        myProcess.StartInfo.FileName = "dsmod.exe"
        myProcess.StartInfo.Arguments = "computer " & Chr(34) & sLDAP & Chr(34) & " -desc " & Chr(34) & sNewDesc & Chr(34) & " -disabled yes"
        myProcess.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)
        myProcess.StartInfo.RedirectStandardOutput = True
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.UseShellExecute = False
        myProcess.Start()
        Do Until myProcess.StandardOutput.EndOfStream = True 'Code breaks here (albeit with no exception, and jumps to the message box.
            sReturnData = myProcess.StandardOutput.ReadToEnd
        Loop
        MsgBox(sReturnData)
        myProcess.Dispose()
 
What do you mean by "breaks"? If there's no exception then there's nothing wrong. It simply means that EndOfStream is True immediately so it never enters the loop. Maybe you should look at handling the OutputDataReceived event rather than trying to read immediately. Never tried it but it sounds logical.

Also, that loop doesn't really make sense. If you call ReadToEnd then you're reading to the end of the stream, so EndOfStream is always going to be True after, at most, one iteration, so what's the loop for at all?
 
Perhaps the better way to explain it would be to say I get output in one program, not the other using the exact same code.

The expected result is a success message. Program A runs fine the standard output returns results. Program B does not run, and returns no standard output. Yet, both programs run identical code.
:mad:

It boggles my mind.
 
I resolved my own issue.

Apparently the process was failing on my x64 PC only. When I compiled and ran the same code on an x86 PC it ran fine. So I changed the code to target x64, and now it works fine on x64.

When I created the second application, it defaulted to "Any" platform, and therefore ran as a x64 app, which is why it worked.

Thanks for your assistance.
 

Latest posts

Back
Top