-
January 5th, 2009, 02:28 AM
#1
Making Gui for console Application
I have a console application which has already been compiled .I have no code with me . I want to invoke this app through GUI GUI . What is the best time saving maneuver to do that .
Also the application was released in .net Framework 2.0 and now I'm going to release it for .net Framework 3.5. It won't make a difference because I'm assuming that the classes haven't been altered that vigorously by Microsoft.
Anyway How can I provide input to a console application using GUI and retrieve the output inside my GUI?
I hope my question is making somewhat sense to all of you??
As requested Here are my restrictions:
1. I only have a console application ,No source code is available for that ,nor do i have any access.
2. I 've build a GUI that is needed , Now what I want to do is that I want on invoke the console application using the GUI that I've created .
For instance the console application works on inputs X,Y and Z and gives the Output 'O'.
i want to pass these X,Y,Z inputs to using a WinForm and the output 'O' will be trapped inside GUI.
I am working on a solution like I'm trying to use System.Diagnostics.Process.Start method to call the console application, passing whatever command line arguments .
is there any other solution that is more effective than this?
Last edited by Abhishek Chauhan; January 5th, 2009 at 07:09 AM.
-
January 5th, 2009, 03:14 AM
#2
Re: Making Gui for console Application
if i want to convert a Console application to GUI (windows form) i go this way:
1- first a analyze the console code to understand its logic, flow of it, class diagrams (if the code was object oriented), static methods, Global variables, data structure, patterns(if used), IO behaviour of the code
2- start the design process for the counter-part GUI application:
2-1: in this phase i decide for the layout of the GUI (scetching it on paper will be a help)
2-2: Decide what kond of windows model would be better for the program (base on a single form, MDI model, mutiple forms)
2-3: Decide about how to design interface for issuing command to the application: e.g. do i need to use Menu, Context Menu, Tool Bar or only simple buttons
2-4: IO Issue: what control i need to get input from the user and showing output:
e.g.:
- only labels and textboxes
- do i need listbox, dropdownlist, radio buttons, check boxes, numericupdown
- do i need filebrowser, folder browser, savedialog, fontdialog, printdialog, colordialogue
- do i need progress bar, status bar, groupbox, tabcontrol
- do i need graphic (GDI+)
3- i adhere to Code-Reuse and Absraction conventions and try to minimize the code i should write for this transition from console to GUI.
example:
- if any .dll was used in the console i use also for GUI
- if the object model of the console does not need to be revised (either it is ok or the goal is not to do any enhancment; just doing transition in the simplest form of it) i use the same object model in the GUI also
- which method goes where: e.g. RetriveData() method goes to click event of a button; which output goes where: e.g. after sorting a list output goes to ListBox
4- Threading Model of the program:
- is single thread enough (in most cases anser is yes)
- do i need to use Multi-Threading
- can BackgroundWorker class help having better performance for the program.
5- Backward Compatibility: Migration from .Net 2.0 to 3.5 is no problem.
Please rate my post if it was helpful for you. Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
January 5th, 2009, 03:24 AM
#3
Re: Making Gui for console Application
Originally Posted by Abhishek Chauhan
Anyway How can I provide input to a console application using GUI and retrieve the output inside my GUI?
Are you hoping to 'wrap' your console application with a UI and communicate with the app using std stream? Or do you expect to rewrite your console app and move the code into a GUI application?
-
January 5th, 2009, 03:28 AM
#4
Re: Making Gui for console Application
I'm hoping to somehow use already existing console application with GUI. I don't have the time to rewrite application again and it is a very huge application .
Also I have not been provided with any source code
Last edited by Abhishek Chauhan; January 5th, 2009 at 03:46 AM.
-
January 5th, 2009, 03:33 AM
#5
Re: Making Gui for console Application
Originally Posted by Abhishek Chauhan
I'm hoping to somehow use already existing console application with GUI. I don't have the time to rewrite application again and it is a very huge application .
Also I have not been provided any source code
IMO that approach usually takes longer than porting the relevant portions of source code into the GUI app. Of course, if you don't have access to the source code, you don't have much choice.
-
January 5th, 2009, 05:17 AM
#6
Re: Making Gui for console Application
Also I have not been provided with any source code
Do you have access to the source code ?
In any case if this is a well designed application, be it console or not, the 'operations' end should be in a dll. Assuming this app was created by the company you're working for you should be able to interface a GUI to this dll.
If course if this isn't the case then you're looking at building up a command line using your GUI, executing the console app trapping its output and error streams and then presenting these to the user.
Darwen.
-
January 5th, 2009, 06:59 AM
#7
Re: Making Gui for console Application
@OP: it would be better that you mention your restrictions in your first post to save me and others to give you solution base on your restrictions.
Please rate my post if it was helpful for you. Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
January 5th, 2009, 07:11 AM
#8
Re: Making Gui for console Application
@ toraj58: I've updated the thread with restrictions and the way I'm trying to solve the problem.
Thanks for your Patience ,I really appreciate that
-
January 5th, 2009, 07:13 AM
#9
Re: Making Gui for console Application
Originally Posted by darwen
Do you have access to the source code ?
In any case if this is a well designed application, be it console or not, the 'operations' end should be in a dll. Assuming this app was created by the company you're working for you should be able to interface a GUI to this dll.
If course if this isn't the case then you're looking at building up a command line using your GUI, executing the console app trapping its output and error streams and then presenting these to the user.
Darwen.
Hi,
I have a similar problem, how do you trap the the outputs? Utilizing Spy++?
-
January 5th, 2009, 07:19 AM
#10
Re: Making Gui for console Application
Here's the direction I'm working on .I got it from some other form and seems to do the trick for me
Create your GUI application as normal. In it you can use the System.Diagnostics.Process.Start method to call the console application, passing whatever command line arguments you like:
Code:
string assemblyDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
Process process = new Process();
process.StartInfo.FileName = assemblyDirectory + "\\console.exe";
process.StartInfo.Arguments = "arguments";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
string standardOutput = process.StandardOutput.ReadToEnd();
string standardError = process.StandardError.ReadToEnd();
process.Wait*****it();
Last edited by Abhishek Chauhan; January 5th, 2009 at 08:29 AM.
-
January 5th, 2009, 07:28 AM
#11
Re: Making Gui for console Application
How about this? Use the process class to launch the .exe, and redirect the standardouput. You can than use your .net application to read the stream.
http://msdn.microsoft.com/en-us/libr...ardoutput.aspx
Code:
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.Wait*****it();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.Wait*****it();
the ****** got blocked by codeguru.... means Wait For Exit (without the spaces)
OH SNAP! You posted while I was in the middle of looking for a quick example to give you ideas. I think your on the right track.
Last edited by Traps; January 5th, 2009 at 07:35 AM.
-
January 5th, 2009, 07:59 AM
#12
Re: Making Gui for console Application
One more. You can add an event to your ouput. Read each line as it is produced.
http://msdn.microsoft.com/en-us/libr...rreadline.aspx
Code:
' Redirect the standard output of the net command.
' Read the stream asynchronously using an event handler.
netProcess.StartInfo.RedirectStandardOutput = True
AddHandler netProcess.OutputDataReceived, _
AddressOf NetOutputDataHandler
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|