By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Redirect StandardOutput problem

P: n/a
I have a perl script that I am calling from vb.net as a process. I need to get the standard
output and display it in a text box. The problem I am having is that extra blank lines are
being added to the standard output, 2 of them per line. I have no idea why - and if I
run the same script in the command line the output is normal (no extra 2 lines per line).
Can someone point me in the right direction? Thanks.

Dim MyProcess As New Process
MyProcess.StartInfo.UseShellExecute = False
'redirect the standard output
MyProcess.StartInfo.RedirectStandardOutput = True
'do not create a command window
MyProcess.StartInfo.CreateNoWindow = True
'set the file name
MyProcess.StartInfo.FileName = "c:\perl\bin\perl.exe"
MyProcess.StartInfo.Arguments = "e:\test_template.pl"

'start the process
MyProcess.Start()

'grab the contents of the standard output
Dim srOut As StreamReader = MyProcess.StandardOutput

Dim sOut As String = srOut.ReadToEnd

txtText = sOut

'wait until the program exits
MyProcess.WaitForExit()
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Darren,

I use this (it is not really optimized)

Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop

I hope this helps?

Cor
Nov 20 '05 #2

P: n/a
Thanks for the suggestion, but it gave me the same undesired result. Is it possible that I need to change the encoding or something like that, and if so how can that be done on standard output?

"Cor Ligthert" wrote:
Hi Darren,

I use this (it is not really optimized)

Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop

I hope this helps?

Cor

Nov 20 '05 #3

P: n/a
Hi Darren,

Would be strange to me, normally it can only send 8 byte extended ascii to
the standard output device in my opinion. (Not that I am sure of this,
however this are mostly classic DOS commands which are used).

Do you see strange characters when you start it by hand? Or empty rows?

Cor
Nov 20 '05 #4

P: n/a
The output when directed to the screen is perfect, no extra line breaks. Only when I redirect the standardoutput to a string or to a textbox do the extra line breaks appear.

"Cor Ligthert" wrote:
Hi Darren,

Would be strange to me, normally it can only send 8 byte extended ascii to
the standard output device in my opinion. (Not that I am sure of this,
however this are mostly classic DOS commands which are used).

Do you see strange characters when you start it by hand? Or empty rows?

Cor

Nov 20 '05 #5

P: n/a
Hi Darren,

Are you really intrested what it is or can you do it with this
redirectstring = redirectstring.replace(chr(10),"")
redirectstring = redirectstring.replace(chr(13),"")

Cor
Nov 20 '05 #6

P: n/a
No, I need to keep the valid line feeds in the file. Thanks.

"Cor Ligthert" wrote:
Hi Darren,

Are you really intrested what it is or can you do it with this
redirectstring = redirectstring.replace(chr(10),"")
redirectstring = redirectstring.replace(chr(13),"")

Cor

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.