Process opens program window when outside Visual Studio

T

tomko

Hi,

My program uses the Process class to start a bat file that starts an
exe. When I run my program inside Visual Studio (debug) the bat and exe
run in the background (are not visible) and all their output is
redirected to my stream reader.

But when I try to run my program outside the IDE, the exe starts in
it's own window and my prgram is put on hold. When I exit the started
program the output of the bat is flushed to my stream.

Why does this work when I'm inside Visual Studio but not outside?!

Here is the simple code I use to start the bat...

prog= new Process();
prog.StartInfo.FileName = executable;
prog.StartInfo.UseShellExecute = false;
prog.StartInfo.RedirectStandardInput = true;
prog.StartInfo.RedirectStandardOutput = true;
prog.StartInfo.CreateNoWindow = true;

if(arguments != null)
{
prog.StartInfo.Arguments = arguments;
}

I hope somebody knows an answer, otherwise weeks of work will go down
the drain.

Br,
Tom
 
C

Chris Dunaway

tomko wrote:

In Line...
Why does this work when I'm inside Visual Studio but not outside?!

Here is the simple code I use to start the bat...

prog= new Process();
prog.StartInfo.FileName = executable;

What is the value of the executable variable? Is it a string? What
does it contain? The name of the batch file? Does it show the black
DOS screen when you run it outside the IDE? Is that what you mean when
you say it shows it's own window?
prog.StartInfo.UseShellExecute = false;
prog.StartInfo.RedirectStandardInput = true;
prog.StartInfo.RedirectStandardOutput = true;
prog.StartInfo.CreateNoWindow = true;

if(arguments != null)
{
prog.StartInfo.Arguments = arguments;
}

Here is the code I use to start a batch file. Notice that I run
cmd.exe and not the batch file directly. This is in VB2005 so I use
the Using statement. If you're not using VB2005, you'll have to
dispose of the Process manually.

Using m_Process As New Process()
With m_Process.StartInfo
.FileName = "cmd.exe"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardOutput = True
.Arguments = "/C c:\test\test.bat"
End With

m_Process.Start()
m_Process.WaitForExit(5000)

Dim output As String = m_Process.StandardOutput.ReadLine()
While output <> Nothing
TextBox1.Text &= output & vbCrLf
output = m_Process.StandardOutput.ReadLine()
End While
End Using

Hope this helps
 
T

tomko

If I run my program outside the ide the program opens a dos prompt
window... this doesn't happend insde the window.

It seems that program executed by the bat file prints out a header
inside ascii 1 characters. The affect of this seems to be omitted
inside the ide where the special characters are only printed in the
consolde window... but outside the ide they force windows to open a new
dos window for the program.

How can I prevent this?
 

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