jhieb
asked on
Dos process in text window
Hello,
I just created a simple vb form that has a text box and a button. The text box contains a file I want to work with. The button executes a batch file I wrote and receives %1 from the textbox. The one thing I don't like is that the batch file runs outside of the form. How can I run the batch file from within the form? Would I do this in a text box?
Please remember I don't know much about vb except for what I am learning in my MS Visual Basic.NET Step by Step book. In your example please show me how to display the batch process in my form and/or how to execute the command line without having to call a batch file and run that in the text window.
Thanks,
John
PS: For your example, let's say the dos command line is Doit.exe <filename>.
Thanks
I just created a simple vb form that has a text box and a button. The text box contains a file I want to work with. The button executes a batch file I wrote and receives %1 from the textbox. The one thing I don't like is that the batch file runs outside of the form. How can I run the batch file from within the form? Would I do this in a text box?
Please remember I don't know much about vb except for what I am learning in my MS Visual Basic.NET Step by Step book. In your example please show me how to display the batch process in my form and/or how to execute the command line without having to call a batch file and run that in the text window.
Thanks,
John
PS: For your example, let's say the dos command line is Doit.exe <filename>.
Thanks
ASKER
Daij-Djan,
Thank you for your response but it doesn't help me at all. Please re-read my question if you would like to respond again.
Thanks,
John
Thank you for your response but it doesn't help me at all. Please re-read my question if you would like to respond again.
Thanks,
John
Here is code that has worked for me.
I am a C# programmer, I tried to translate it to VB as best I could...
anyway, here is some code. This will call program from within your VB program and execute it.
<C#>
using System.Diagnostics;
Process DOS = null;
ProcessStartInfo qOptions = new ProcessStartInfo("cmd.exe"
qOptions.UseShellExecute = true;
qOptions.WindowStyle = ProcessWindowStyle.Hidden;
DOS = Process.Start(qOptions);
DOS.WaitForExit();
<VB>
imports System.Diagnostics
Dim DOS as Process
DOS = null;
Dim qOptions as new ProcessStartInfo("cmd.exe"
qOptions.UseShellExecute = true
qOptions.WindowStyle = ProcessWindowStyle.Hidden
DOS = Process.Start(qOptions)
DOS.WaitForExit()
for your code, instead of -- ProcessStartInfo("cmd.exe"
you will want
ProcessStartInfo("myBatchF
It might not be ellegant but it sure works. Even after rereading your q I do think so.
Ups :P I finally understood your q It won't do.
ASKER
Hi _TAD_,
Your code looks like it will work. I ran it as a test, and even used your same command line. For some reason, nothing appeared in the mmm.dat file. It got created but it was empty.
Also, I would like to have the process displayed in a Dos window. Am I saying that correctly? The code you gave looks like the code I will use but I think something is still missing. I want that code to run in a text window, or some sort of window, so that when I start the process from a form, the process and progress displays in some sort of box within the form.
Please let me know what you think and if I need to explain this a little more.
Thank you,
John
Your code looks like it will work. I ran it as a test, and even used your same command line. For some reason, nothing appeared in the mmm.dat file. It got created but it was empty.
Also, I would like to have the process displayed in a Dos window. Am I saying that correctly? The code you gave looks like the code I will use but I think something is still missing. I want that code to run in a text window, or some sort of window, so that when I start the process from a form, the process and progress displays in some sort of box within the form.
Please let me know what you think and if I need to explain this a little more.
Thank you,
John
There is a line in the code:
qOptions.WindowStyle = ProcessWindowStyle.Hidden
If you change this to:
qOptions.WindowStyle = ProcessWindowStyle.Normal
--or--
qOptions.WindowStyle = ProcessWindowStyle.Maximiz
--or--
qOptions.WindowStyle = ProcessWindowStyle.Minimiz
You will get a DOS window that pops up.
Are you using VB.Net or C#?? I know the C# code works (I've used it in a program), the VB code on the other hand is only a translation of the C# code. It *should* work, but I haven't tested. I'll take a look at it and fine tune it a bit. If it's not working properly for you then there must be something wrong with my translation.
-----
OH!!! Check to make sure that you have a "C:\Temp" directory!!! That directory is one that I've created for my own personal use. Windows by default does not C:\temp\directory
<C#>
ProcessStartInfo qOptions = new ProcessStartInfo("cmd.exe"
<VB>
Dim qOptions as new ProcessStartInfo("cmd.exe"
try changing these to the following, it may help:
<C#>
ProcessStartInfo qOptions = new ProcessStartInfo("cmd.exe"
<VB>
Dim qOptions as new ProcessStartInfo("cmd.exe"
-----
As for getting the DOS pop up window to display inside your form... This exact procedure I think is not possible, however there is an easy work around. Even though you cannot display the DOS window directly in your form, you can hide the DOS window completely, and then create your own test window that reads everything that is printed to, and read from the DOS command. I believe there is a way to redirect the DOS streams into .Net streams and then you can simply read the stream as a text stream and display that text stream onto your form.
ASKER
Hi _TAD_,
I noticed that and added the \temp directory. I also changed the window style to normal. But still, I need to explain a little more. Rather than have the dos process display in a separate window, outside of VB, how do I direct the output to be inside the form? Does that make sense? I am not sure if a text window is what I am looking for but I will use that in my example.
1. The form has a button at the top that says START
2. There is a text window which has the name of the particular process I want to start. I type that in.
3. There is an additional text window that displays the dos process I run when pressing START.
Rather than have the dos process run apart from the form, I want it to run inside the text window (or whatever type of window it needs to be) on the form.
I suspect that your code is close to what I am looking for. Everything I have researched has pointed me to System.Diagnostics. So, I will use that. But, still the mystery is how do I redirect the display output into a text window from within the form rather than the dos window running outside the form.
Thanks,
John
I noticed that and added the \temp directory. I also changed the window style to normal. But still, I need to explain a little more. Rather than have the dos process display in a separate window, outside of VB, how do I direct the output to be inside the form? Does that make sense? I am not sure if a text window is what I am looking for but I will use that in my example.
1. The form has a button at the top that says START
2. There is a text window which has the name of the particular process I want to start. I type that in.
3. There is an additional text window that displays the dos process I run when pressing START.
Rather than have the dos process run apart from the form, I want it to run inside the text window (or whatever type of window it needs to be) on the form.
I suspect that your code is close to what I am looking for. Everything I have researched has pointed me to System.Diagnostics. So, I will use that. But, still the mystery is how do I redirect the display output into a text window from within the form rather than the dos window running outside the form.
Thanks,
John
ASKER
Points increased to 150
ASKER
_TAD_'s answer has helped me out with part of my question. I am still looking for a way to direct the DOS window to display within the form and not outside of it. I am sure this should be easy enough to do.
If you look at the above code for vb.net you will have to modify a couple items. First of all DOS = null; is used in vb 6 and was replaced in vb.net. The other item is the path for the mm.dat text file (in the example). I removed the double \\ and the text file created correctly. The \\ may need to be in there but I don't know why. It works without it.
This question is still open. If you know how to place the dos window inside of a form please let me know how to direct the display.
Thank you,
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the dilligence, _TAD_ . I haven't tried this yet but I can tell it will work. Great job!
allocate a console for your app
hide it
reroute its input ising its in/out/error properties
writeline to it to simulate input. Using a different input source this could be modified.