Problem running BAT file containing CHCP

P

Peter Macej

I need to run external BAT file and print it's output from my
application. I use the following code:

Dim prs As New System.Diagnostics.Process()
prs.StartInfo.UseShellExecute = False
prs.StartInfo.FileName = "C:\mybat.bat"
prs.StartInfo.RedirectStandardOutput = True
prs.StartInfo.CreateNoWindow = True
prs.Start()
prs.WaitForExit()
Dim sr As System.IO.StreamReader = prs.StandardOutput()
output = sr.ReadToEnd()

This works fine if the bat file doesn't contain CHCP command. If the bat
file contains CHCP command, this command doesn't execute (Win XP Pro,
SP2). Normally, CHCP without parameters outputs something like
Active code page: 1250
I get the correct output when I run bat file manually. But when it is
called from my VB .NET application, CHCP prints no output and what's
worse, it doesn't change codepage when it is called with parameters. I
need to change codepage if some paths in the bat file contain characters
with diacritics e.g. Slovak or Scandinavian.

I found that BAT file runs correctly if
prs.StartInfo.RedirectStandardOutput = True
However, I cannot get its standard output and I must to redirect it to
file using
prs.StartInfo.Arguments = ">c:\a.log"
and then read a.log file. I don't like this solution and I'm curious why
it doesn't work as expected.

Has anyone experienced similar problem and found solution?
 
H

Herfried K. Wagner [MVP]

Peter Macej said:
I found that BAT file runs correctly if
prs.StartInfo.RedirectStandardOutput = True

You mean '... = False', don't you?
 
P

Peter Macej

I found that BAT file runs correctly if
You mean '... = False', don't you?

Yes, sorry. If
prs.StartInfo.RedirectStandardOutput = False
everything works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top