weird OpenFileDialog Problem with cmd.exe

B

bbembi_de

Hello everyone,

I have a C# program that runs a batch from the command line.
I use the following code for that:

String arguments = "/C CALL batchfile.bat";
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = arguments;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
Process p = Process.Start(startInfo);
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();

This works just fine.

But as soon as I use a OpenFilerDialog in my Program the batch won't
work any more.

OpenFileDialog fileDlg = new OpenFileDialog();
fileDlg .Filter = "PDF|*.pdf|Word|*.doc|All|*.*" ;
fileDlg .FilterIndex = 1 ;
if(fileDlg .ShowDialog() == DialogResult.OK)
{
Stream myStream = null;
if((myStream = fileDlg .OpenFile()) != null)
{
...
myStream.Close();
}
}

Any ideas?
Thanks in advance.

Greetings juergen
 
I

Ignacio Machin \( .NET/ C# MVP \)

HI,

();
This works just fine.

But as soon as I use a OpenFilerDialog in my Program the batch won't
work any more.

I fail to see the connection between the 2 code snipes , are they in the
same method?

Do you get any exception at all?
 
R

Ravi Ambros Wallau

What happens?
Nothing happens?
You know that you can't have modal dialogs in a batch application, don't
you? What do you expect to happen?
The process will be halt on the ShowDialog until an user interacts with your
app...
 
B

bbembi_de

Hi again,

I have a application that does many things. One of them is to execute a
batch in command shell.

And the weird things is that the 2 code snips are not connected.

I choose a file in the openfiledialog and do other things.
then i click start (in my app) and the batch runs.

but it only runs if i didn't use the openfiledialog.
if i use the openfiledialog the commands in the batch won't be
executed.
the command process just returns at once just s if i have a empty batch
file.

funny, isn't it?

greetings juergen
 
R

Ravi Ambros Wallau

Weird...
Are you sure that there's nothing more that is made when you use
OpenFileDialog?
 

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