Redirecting standard output from a process (msxsl.exe) to a string in VB.NET

I am writing a command line application in VB.NET. This application calls another, msxsl.exe, to start the XSL conversion. For this, I use the Process class:

Dim process = New Process()
process.StartInfo.FileName = "msxsl.exe"
process.StartInfo.Arguments = "base.xml test.xsl -o styled.xml"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardOutput = True
process.Start()

This part works great. I want it to be able to display the output from this process on the console of my application. I read a few posts explaining this method, but in this case it does not work. The output is an empty string.

Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
Console.WriteLine(output)

I checked that if I run the msxsl executable file myself (i.e. by running msxsl.exe base.xml test.xsl -o styled.xml), it will display the output on the command line. What am I doing wrong?

EDIT: I should notice that the msxsl process is currently failing due to a garbled XML file. It displays this error message:

"test.xsl".

: 0x800c0006

.

, (, , ).

+3
1

, , , , StandardError, StandardError Process.StartInfo.RedirectStandardError = True, .

Dim ErrorString As String = Process.StandardError.ReadToEnd()

+1

Source: https://habr.com/ru/post/1776707/


All Articles