|
adam.m.b.nelson wrote: 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.
|
|
|
|
|
Granted I am completely and utterly lost, but from the examples I have seen everything seems to be "right" but it still doesn't work.
Let's simplify this and say I simply want to write a line to the CMD window, from my GUI, and leave it sitting there staring at me. This program below should do that, NO?
private void btnKapow_Click(object sender, EventArgs e)
{
Process Temp = Process.Start("C:/Windows/System32/cmd.exe");
Temp.StartInfo.UseShellExecute = false;
Temp.StartInfo.RedirectStandardInput = true;
Temp.Start();
Temp.StandardInput.WriteLine("Test");
Temp.Close();
}
I'm completely out of my domain here, I'm an embedded programmer, and have built some GUI's in the past without an issue, but this single process is far more indepth than anything I have done before.
|
|
|
|
|
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.
|
|
|
|
|
OK, I am starting to understand the issue. I had noticed it looked like there were two windows for an instant, but i attributed it to one of the Win7 window effects. So what is likely happening is there are actually two windows, and the one just opens and closes so fast that I can't see it?
To use the 'atprogram' the only route i can find into it is to use the StudioCommandPrompt located here "C:/Program Files (x86)/Atmel/Atmel Studio 6.0/extensions/Application/StudioCommandPrompt.exe". Once its open I need to run these commands:
atprogram -t avrispmk2 -i isp -xr -d ATmega328 -v chiperase
atprogram -t avrispmk2 -i isp -xr -d ATmega328 write -fs --values 7FD9FF
atprogram -t avrispmk2 -i isp -xr -d ATmega328 program -f Example.hex
After each step the window spits out some pass fail information.
There are alternative command line programming options, but that is the one I learned first.
This all makes a lot more sense now that I know the window is opening and closing very fast, it actually explains a lot. We're at the end of the day here, but first thing in the morning I'll try pumping in program commands like that and see if it works.
This whole time I saw an idle window sitting there, and assumed it meant the input hadn't been received.
Thanks for your help and patience, I will update tomorrow morning.
|
|
|
|
|
Slightly off topic, but given that you are (apparently) using Atmel Studio[^] to develop some embedded code application, what exactly is this C# program supposed to be for?
|
|
|
|
|
Yeah, AVR wasn't my decision, but that's another story. The C# GUI is part of an automatic test rig that tests all the functionality of our boards, then programs various aspects of the boards. It tests (currently) 7 boards at a time, but we will soon be expanding it.
Everything but the automatic programming is already working. I left it for last because I thought it was going to be the easy part :P
|
|
|
|
|
Sorry for the late response, I haven't been on in a while. The C# side was a computer based GUI to control the automated testing, and display results.
|
|
|
|
|
adam.m.b.nelson wrote: What "Settings" are you referring to when you said I should check the settings? Any of the properties of the Process , or its StartInfo .
|
|
|
|
|
Hmmm, I've looked through those settings pretty thoroughly. The problem definitely seem to be in the stream-writer. There are two of us working on this issue, on different machines and neither of can get text into a normal command prompt (but the debugger command prompt).
Can I see the code you wrote to test it? Maybe it will shine some light on our issue.
|
|
|
|
|
First of all test StudioCommandPrompt to find out if it is using the standard input, output and error streams correctly.
Here is an example of how it's done using the command processor, cmd.exe, which everyone should have.
At a command prompt enter
cmd < inputcommands.txt > stdout.txt 2>stderr.txt
This will start a new cmd.exe which will take redirected input from the file inputcommands.txt . Standard output will be redirected to the file stdout.txt and standard error to stderr.txt .
A suitable inputcommands.txt is
time /t
date /t
non-existent.exe
exit
Simple stuff: output the date, the time, try to exec an app that isn't there (to cause an error) and then exit.
Here is the contents of the output files
stdout.txt
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
XXXXXXX>time /t
17:47
XXXXXXX>date /t
14/02/2013
XXXXXXX>non-existent.exe
XXXXXXX>exit
stderr.txt
'non-existent.exe' is not recognized as an internal or external command,
operable program or batch file.
You would have to come up with a suitable set of inputs for StudioCommandPrompt and then run a similar test.
i.e. At a command prompt enter
StudioCommandPrompt < inputcommands.txt > stdout.txt 2>stderr.txt
It probably would be wise to run this test in steps
1) Check if your app will read from redirected input
StudioCommandPrompt < inputcommands.txt
2) If that's ok, test if output can be redirected
StudioCommandCommandPrompt < inputcommands.txt > stdout.txt
3) and separately test if error can be redirected, or possibly if the error stream is used at all.
StudioCommandPrompt < inputcommands.txt 2>stderr.txt
If it all checks out OK come back to me and we'll take it from there.
Alan.
|
|
|
|
|
Thanks Alan,
I'm going to start with something posted above, then I'll do this too. It'll take me a bit to make the changes.
|
|
|
|
|
ok, I'm an embedded programmer, so that took me a little bit to wrap my head around. I don't think the problem is in the StudioCommandPrompt as I can't get my program to feed input to cmd.exe either. Below is a chunk of test code I put together to just test the connection all together, and it still outputs nothing.
Process Temp = System.Diagnostics.Process.Start("CMD.exe");
Temp.StartInfo.UseShellExecute = false;
Temp.StartInfo.RedirectStandardInput = true;
Temp.StartInfo.RedirectStandardOutput = true;
Temp.StartInfo.RedirectStandardError = true;
Temp.Start();
Temp.StandardInput.WriteLine("Test");
Temp.Close();
|
|
|
|
|
OK here's the improved version of your program (it's a console program)
I'll list what I've done:
1) Fix error: you had used Process.Start twice
2) Assigned a handler for the OutputDataReceived event. Redirected output is prefixed REDIR to differentiate from normal program output.
3) Activated Exited event and and assigned a handler
4) Error not redirected (makes the test simpler)
5) Start reading redirected standard output after Process.Start()
6) Issue DIR command
7) Issue SET command (to dump the environment variables)
8) Issue EXIT command to close cmd.exe
[EDIT forgot this]
9) Don't close the Process object
using System;
using System.Diagnostics;
namespace AdamB {
class Program {
static void Main(string[] args) {
Console.WriteLine("AdamB Test app");
RedirectionTest();
Console.WriteLine("Press Enter to end when output is complete...");
Console.WriteLine();
Console.ReadLine();
}
private static void RedirectionTest() {
Process Temp = new Process();
Temp.StartInfo.FileName = "cmd.exe";
Temp.StartInfo.UseShellExecute = false;
Temp.StartInfo.RedirectStandardInput = true;
Temp.StartInfo.RedirectStandardOutput = true;
Temp.OutputDataReceived += new DataReceivedEventHandler(Temp_OutputDataReceived);
Temp.EnableRaisingEvents = true;
Temp.Exited += new EventHandler(Temp_Exited);
Temp.Start();
Temp.BeginOutputReadLine();
Console.WriteLine("Sending DIR");
Temp.StandardInput.WriteLine("DIR");
Console.WriteLine("Sending SET");
Temp.StandardInput.WriteLine("SET");
Console.WriteLine("Sending EXIT");
Temp.StandardInput.WriteLine("EXIT");
}
static void Temp_Exited(object sender, EventArgs e) {
Console.WriteLine("MESSAGE: The process has exited");
}
static void Temp_OutputDataReceived(object sender, DataReceivedEventArgs e) {
Console.WriteLine("REDIR {0}", e.Data ?? "Null received -> Output stream has closed");
}
}
}
It's not usual for all commands to be issued before any redirected output appears on the screen and for the Exited event to occur while output is still arriving. Output has finished when the redirected stream is closed and that is signalled by e.Data == null.
Understanding all this redirection stuff is not easy if you are taking your cues from the Microsoft documentation as the examples are poor.
I'll look for more questions tomorrow.
Alan.
modified 14-Feb-13 16:40pm.
|
|
|
|
|
Alan N wrote: cmd < inputcommands.txt > stdout.txt 2>stderr.txt
Clever.
Obvious when I saw it but certainly can't remember ever considering that option in the many times I have messed with programmatic access to stdin/out.
|
|
|
|
|
I gave this a quick try yesterday, but I don't really understand what's going on in his example. I assume it didn't work because I broke it :P
|
|
|
|
|
adam.m.b.nelson wrote: but I don't really understand what's going on in his example.
How so? The one file provides input lines. Nothing else.
The output is irrelevant except as a tool to help you.
If you can't get the input lines to work then you need to work on getting the right values or the application is coded in such a way that it will NEVER work with this type of process.
|
|
|
|
|
I am doing final year project on the topic object recognition using c#. I am having problem that I didn't have any idea how to use neural network. Since my concept is to recognize the any types of object having different shape and size like human, ball, car. Since I have very few days so anybody can u help me. plz give me some idea with some sample code of object recognition.
|
|
|
|
|
manoj dhunelg wrote: Since I have very few days Then you have a lot of work to do; start here[^].
|
|
|
|
|
You have "very few days" for a final year project? And you picked THIS topic?? What do you mean by "very few days"?? How many are we talking about?? If it's a couple of weeks, you MIGHT be able to pull this off by pulling very long days to work on this project, but since you don't have any neural network experience, I seriously doubt it.
|
|
|
|
|
Hi
I need to force users to write in and fill forms using "English". And they cant be able to change language by pressing "Alt+ Shift".
thanks a lot for your helps...
|
|
|
|
|
Now that's all very nice, but you forgot to ask a question.
Regards,
Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
This would be tricky. If you just want to ensure script used is English, it is easy. Just scan every character in the input and make sure all the characters are valid English letters. But user can write another language using the English script. Detecting this would be tough and you need to use some natural language processing libraries.
Best wishes,
Navaneeth
|
|
|
|
|
Why does it matter? In "English" you can still type random crap in the form (and if you think that means ascii-only, consider pasting and alt-codes), so you'd still have to deal with it.
|
|
|
|
|
a simple way is in textbox keypress event! check if user pressed alt or shift , show a messagebox and inform to user that he/she cant use this feature
and if user changed language before activating textbox, you can check first charecter with textchanged event, if it is a charecter belong to persian (for example) ... with a message box say to user must change his/her language first
|
|
|
|
|
Spell check using an english dictionary.
|
|
|
|