well lemme explain whats my problem !
i thought writing codes is most simple part of developing ,but after some project which i did ,i found that need to change my coding style ! as you know for one porpuse is many way to achieve ! but i found always choose worst way !
There are a lot of ways to do something, and even we bicker about what is "best". And most of us here will have some "old code" somewhere from years ago that makes 'em go "wtf" today.
Always ask an explanation if there's an opportunity to do so.
well is any book or reference to teach me how i choose best way? at least better way!
You might want to download FxCop; it checks your code using pre-set rules. Another sweet way of learning alternatives is to read existing code (I love meeting new brownfields!) and, again if possible, ask for explanation if something is interesting.
Get lots of practice. Start your own open-source project, so that you'll be forced to "maintain" your own code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
Start thinking about how "programming" skills overlap with the non-programming things you do. Draw on your experience in the other areas of your life to help you improve. For example, work on your writing. Coding is composition and all the rules you learned about writing well apply to your programming: say what you mean; don't use a 10-cent word when a 5-cent word will do; don't mix metaphors (i.e., models); etc.
Hey there! I'm trying to write into a command prompt window (Not the debugger) from my C# GUI with no luck (I've looked at lots of examples), and I'm not sure where I am going wrong. The command prompt window will open, it will accept text if i type it in from my keyboard, but it won't accept it from my application.
I've tried with both the windows command prompt, and the custom one we are trying to write into. Long story short I am trying to access an AtmelAVR programmer from command line to automatically program devices in our assembly process. I can automatically program by command line when I enter the text myself, I just can't get out GUI to do it... I've attached my code below:
EDIT: Working in VS2010 on Windows 7
Any help is greatly appreciated!
Process PrgCommandPrmpt = new Process();
PrgCommandPrmpt.StartInfo.UseShellExecute = false;
PrgCommandPrmpt.StartInfo.FileName = "C:/Program Files (x86)/Atmel/Atmel Studio 6.0/extensions/Application/StudioCommandPrompt.exe";
PrgCommandPrmpt.StartInfo.RedirectStandardInput = true;
PrgCommandPrmpt.StartInfo.RedirectStandardOutput = true;
PrgCommandPrmpt.StartInfo.RedirectStandardError = true;
PrgCommandPrmpt.StartInfo.CreateNoWindow = true;
PrgCommandPrmpt.EnableRaisingEvents = false;
PrgCommandPrmpt.StandardInput.AutoFlush = true;
StreamWriter inputWriter = PrgCommandPrmpt.StandardInput;
StreamReader outputReader = PrgCommandPrmpt.StandardOutput;
StreamReader errorReader = PrgCommandPrmpt.StandardError;
tboxVerbose.AppendText("Doing stuff now!"); //This just outputs to a textbox to let me know something is happening.
string CommandText = "cd..";
inputWriter.WriteLine("WHY DONT YOU WORK"); //These are the two latest ways I tried to write to it, no luck.
PrgCommandPrmpt.StandardInput.Write(CommandText);//These are the two latest ways I tried to write to it, no luck.
I just tested that sample and it works fine. I would suggest you check some of the options you have selected to ensure none of them is conflicting with what you are trying to do. You could also take that working sample and modify it to use the command you wish to run and see what happens.
I'm not sure that we are trying the same thing here. I loaded that example into a new app, and it doesn't write to the console either. I also get an error on this line about a NullReferenceException, presumably as the buffer is empty?
inputText = Console.ReadLine();
if (inputText.Length > 0)
What "Settings" are you referring to when you said I should check the settings?
Well I'm not sure what you are doing wrong. I just copied the code from the link I gave you, then wrote another program that reads and writes to the standard input and output stream, and it all worked. Maybe the fault lies with the program that you are trying to execute; what exactly does it do?
The program we are trying to write into is just a CMDPrompt that has been written to access the programming functions of the AtmelAVR programmer through command line. The commands we need to send resemble the one below:
Nor would it, that just runs an independent process, which changes directory and immediately terminates without producing any output.
I have to say you are maybe getting yourself tied in knots here, by repeatedly trying everything you can think of, without really looking at what you should be doing. Think about what program you are trying to run, how it must be started, what input data it may read and what output it may produce. That should then determine how you need to start it, whether you need to feed it any input (beyond its initial parameters) and whether you should expect to read from its output stream.
Yeah, We are using a command prompt, or command processor as someone just called it (I may be using the wrong name for it). Then all re need to do is to literally send in a line (string) with a carriage return, read the text that comes in, and repeat based off of the text that comes back.
When I started it seemed easy enough to do, but it now seems that its not easy to feed text into a cmd window.
but it now seems that its not easy to feed text into a cmd window.
Yes, it's perfectly easy, but you need to understand what is happening in that window, as I explained in an earlier post. I have not used the Process class before, but by following the rules, and understanding what goes on in the started application, I demonstrated that it works as documented.
Not really. You start the command window, send it a (meaningless) word and then immediately close it. Maybe if you explain exactly what your program is supposed to do, I can offer some more suggestions. Explain:
How is the program invoked manually from a command window.
What, if any, further input commands do you need to type in to the program.
What output is produced by the program on the command window, that you need to capture.
What command, if any, is used to terminate the program.
The answer will not be forthcoming before tomorrow, but I'm sure it's possible to do it.
Last Visit: 31-Dec-99 19:00 Last Update: 1-Apr-15 20:03