|
I believe you must be using the Process class to run you console application, in which case you can use the Process.StandardOutput[^] to get a StreamReader object to read the output from you console app.
|
|
|
|
|
I think it would be better to reorganize your code. The console project you wrote really should be a library/API, if you're going to consume it from another application (ie, the windows service).
I'd suggest converting your console application into a class library project. Then, both the windows service and console can create their own implementations. So, let's say you execute the console app like this:
myconsoleapp.exe "servicename"
Then, create a library project with a public method "RunService":
public class MyAPI
{
public string ExecuteService(string serviceName)
{
}
}
Now both the console app, and your new windows service can consume MyAPI as needed.
|
|
|
|
|
dbaseman wrote: Now both the console app, and your new windows service can consume MyAPI as needed
Of course it would require quite a bit more work than that. After all it probably takes input, and that would need to be dealt with. And it definitely creates output, which the OP mentioned, and that too would need to be dealt with.
|
|
|
|
|
Right, of course, but my point is that it's far better to interact with an API, than trying to parse the output from a console application.
|
|
|
|
|
dbaseman wrote: but my point is that it's far better
No not really.
Sometime it can be much better not to do it that way. For example, if one has a server and one needs to interact with unmanaged C++ code in C# where the C++ code is known to be flaky (or even might be.) Because one doesn't want the server to exit every time the C++ code throws a system exception.
Or because one doesn't have the original code. Or doesn't have a license to modify it. Or because one has a number of applications, all supporting the same idiom (console) and a single solution versus numerous others is more cost effective.
|
|
|
|
|
I never really liked console apps, here is what I would do.
Create a windows forms app that will allow you to input information, a button and a display control.
The input will be specific to our needs and set the defaults to the test information.
The button will call the method you use in the console app
The output (I usually use a listbox ot a textbox) will take the output you are currently using.
I find this the easiest way to debug an console app that has been snaffled from the interweb. Make sure you keep all your processing (the console methods) in a seperate class as it is then easy to create a library class from that (as jschell suggested).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a question about how to obtain the results, condition codes and messages from a C# 2008 console application.
Basically I have received the C# 2008 console application code that calls a remote webservice and consumes the results. The console application runs by giving it commands to know what method in the web service to call.
Now I am going to write a C# 2010 service application that will call the C# 2008 console and run the commands in a specificed order. There are three types of calls that need to be called in a specified order.
This new application will call the console application by executing the commands in a spcific order. However, I would like to know how this new application can obtain the results of the console application.
How will the console application pass it's results back to my new application?
Would it be better if I put the code I am describing in the application I am referring to? If so, can you tell me why and how to accomplsih that task?
|
|
|
|
|
Hi,
You can't directly call the console application methods. you can create command line argument to execute methods inside your application in order. But to get the result from the application you may need some class defined in your application. Instead i suggest you to create one Class library and shift your all logic in your class library. Then use this library in your service as well as in your Console application.
Hope this works for you
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
Do you have access to the source of the console application? If so, include it in your new application and modify it accordingly so that it has methods you can call which return something or give you events.
If not: does it have an API specified that isn't just the command line? There may be public methods available which do what you want.
Finally, if you just have a console app and no other way into it, you can redirect its stdin, stderr and stdout and read its output from there. This is quite a fragile approach so it isn't something you should do unless you have to.
In this case you say that the console application is talking to a web service. Can't you just talk to the web service directly?
|
|
|
|
|
In a C# 2008 console application, the log file must be redirected to a dos popup window since that is what I see in the dos popup window. I do not see any kind of log files being saved. Thus can you tell me how to change code that goes to the dos popup menu and have the results saved to a log file instead?
|
|
|
|
|
I'm not sure I understand your problem, but if you just want to save results to a log file rather than printing to the command window, then open the file, write to it and close it. Here's what I do to save computed results in a console app.
StreamWriter outFile1 = new StreamWriter(FILENAME1);
outFile1.WriteLine(Heading);
outFile1.WriteLine(Title + DateTime.Now.ToString());
...
...
outFile1.WriteLine("Termination due to " + TerminationReason);
outFile1.WriteLine();
outFile1.Close();
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Actually you have two problem as i can see,
1) you would like to store log information somewhere.
Ans: To write log in log file you need to implement some logging in your application. i suggest you to use Log4Net. You can found lots of example for log4net configurations here.[^].
2) You want to show your 2nd console window when error occur.
Ans : See this[^] discussion to open new console window and you can print your log in it.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
Am I to understasbd that this is an existing third-party app over which you have no control?
|
|
|
|
|
Since I am new to working with C# 2008 desktop application, I have the following questions to ask since I need place files in a directory path that looks like D://app1/test/mm-dd-yyyy/customer number/type of document being worked on:
1. How would you code the month-date-year format (mm-dd-yyyy) part of the path?
2. The path of the path that stays the same is D://app1/test/. The dynamic part of the path is mm-dd-yyyy/customer number/type of document being worked on.
Thus can you tell me how to code the static part of the path and setup the dynamic part of the path so that I can place files in the dymanic part of the path?
3. Once I have the new path location, can you tell me how to place files in the new directory path location?
|
|
|
|
|
First off, use an ISO 8601-compliant format: System.DateTime.Now.ToString ( "yyyy-MM-dd" ) ; , you'll thank me later.
Then, look at Path.Combine (String, String, String, String)
[^]
And explore the System.IO.Path class for any other details you need.
|
|
|
|
|
Your answer about System.DateTime.Now.ToString ( "yyyy-MM-dd" ), why would I use this format?
I am required to put the dymanic file in the directory structure of mm-dd-yyyy.
|
|
|
|
|
Because yyyy-MM-dd is far superior and an international standard.
If you use any other format, your files won't sort properly.
The other format was likely specified by an idiot and you need to educate that idiot.
|
|
|
|
|
Listen to Piebald on this one, go educate the the idiot and use the 'yyyy-mm-dd' format. To help with this make up a list of file names using the same prefix and the 2 date formats, sort them and get the idiot to find a particular date/file
Oh and the rest of his recommendation is valid as well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all,
I use the following code to select the next control.
private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
SelectNext_control(opdrachtnummerTextBox.Tag.ToString());
}
}
private void SelectNext_control(string t)
{
bool isNextControl = false;
int TagToFind = (int.Parse(t));
do
{
TagToFind++;
foreach (Control c in this.Controls)
{
if ((c.Tag != null)&&(c.Visible=true))
{
if (c.Tag.ToString() == TagToFind.ToString())
{
isNextControl = true;
c.Select();
}
}
}
if (TagToFind > 102) break;
} while (!isNextControl);
}
All controls are tagged with an incremented number.
What to do if the next control is in a groupBox?
Thanks,
Groover.
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
If it is in a groupbox, then you have to recursively search into each container control - which would also cover panels and so forth.
But why not do it the easy way? Put the next control reference into the tag directly, instead of a number?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
To put the next control reference into the tag directly, instead of a number cannot be done because e.g the third control can be a listbox and the Visualibility property of other controls an groupBoxes depend on the selection in the listbox or checkboxes.
Can I use the TabIndex instead?
Thanks,
Groover.
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Instead of abusing the Tag , how about adding them to a List? No matter where they'd be located, you'd always have a reference.
Alternatively, use the name-property.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I think we need some basic information here:
1. are all Controls in the GroupBox of the same Type ? If so, what Type ? If they are all the same type, why not just manipulate the TabIndex property, and let the Tab key do the work for you.
2. Have you considered the implications that a GroupBox has no 'TabStop property ? (hint: probably none !). Note that a Panel has a 'TabStop property. Run-time behavior (tabbing between Controls in a GroupBox will work as expected).
3. are Controls added at run-time to this GroupBox ?
Since the last control added will have the highest TabIndex (and assuming TabStop set to 'true, and that it has a 'TabStop propery: what's the problem here.
4 issue of nested-containers as raised by OriginalGriff: if you have properly adjusted the TabIndex: I see no reason for a recursive descent here: tabbing from one Panel to another and, within the second Panel, "into a third Panel:" is no problem.
So, I think to really understand if you have a unique problem here, we need to know much more about your UI structure, and the way you intend use of the Tab key to work.
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way:
Interfaces
IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.)
* string Title; - The title of the quiz
* string SubTitle; - The subtitle of the quiz
* List<iquestion> Questions; - A collection of questions which are part of the quiz
* void AddQuestion(IQuestion question);
* void RemoveQuestion(IQuestion question);
IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz)
* string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!)
* int Points; - The amount of points the question is worth
IAnswer - Answer interface; contains information about an individual answer for an IQuestion
* string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No")
* bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions)
And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface.
class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion
class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer
For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List<ianswer> field is auto-generated by the class, since "True" and "False" are the only 2 options.
I hope this makes sense to everyone. Haha. I'm just trying to find out if I'm getting the concept fairly well. Or what I may need to do in order to improve in this topic.
Again, it works as expected. I can easily extend the code to support various question and answer types. That seems to be the basic concept. But still, I wanted to ask.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Seems silly to split up IQuestion and IAnswer. You're never going to have a MultipleChoiceQuestion paired up to a TrueFalseAnswer for example, so that should be a single object IMO. An IQuestion+Answer type object. Even if you kept your design, I see no way of actually mapping a question to an answer.
|
|
|
|