471,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

weird OpenFileDialog Problem with cmd.exe

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

Feb 13 '06 #1
4 2294
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?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 13 '06 #2
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...

<bb*******@lycos.de> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Feb 13 '06 #3
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

Feb 14 '06 #4
Weird...
Are you sure that there's nothing more that is made when you use
OpenFileDialog?
<bb*******@lycos.de> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Feb 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris Mantoulidis | last post: by
2 posts views Thread by Bill Nguyen | last post: by
reply views Thread by piesse | last post: by
6 posts views Thread by jsamdirect | last post: by
9 posts views Thread by mrstevegross | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.