By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

WPF and Standard Output redirection - Weird Error

P: n/a
Hi All,

I wanted to develop a WPF application to capture the output of a
command line program and display it in a GUI.

However I get a weird error in the following code:

System.Diagnostics.Process pfadminProc = new
System.Diagnostics.Process();
pfadminProc.StartInfo = new
ProcessStartInfo();
pfadminProc.StartInfo.RedirectStandardInput = true;
pfadminProc.StartInfo.RedirectStandardOutput = true;
pfadminProc.StartInfo.RedirectStandardError = true;
pfadminProc.StartInfo.FileName = "process";
pfadminProc.StartInfo.Arguments = "arguments";
pfadminProc.Start();
StreamReader outputReader =
pfadminProc.StandardOutput;
pfadminProc.WaitForExit();

When I try to execute the last line, I get an error saying that some
"Window1.xaml" resource could not be found. What in the world does
*executing a process* have anything to do with the XAML files. Can
somebody enlighten me??

Thanks,
Sundar

Nov 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"sundarvenkata" <su***********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi All,

I wanted to develop a WPF application to capture the output of a
command line program and display it in a GUI.

However I get a weird error in the following code:

System.Diagnostics.Process pfadminProc = new
System.Diagnostics.Process();
pfadminProc.StartInfo = new
ProcessStartInfo();
pfadminProc.StartInfo.RedirectStandardInput = true;
pfadminProc.StartInfo.RedirectStandardOutput = true;
pfadminProc.StartInfo.RedirectStandardError = true;
pfadminProc.StartInfo.FileName = "process";
pfadminProc.StartInfo.Arguments = "arguments";
pfadminProc.Start();
StreamReader outputReader =
pfadminProc.StandardOutput;
pfadminProc.WaitForExit();

When I try to execute the last line, I get an error saying that some
"Window1.xaml" resource could not be found. What in the world does
*executing a process* have anything to do with the XAML files. Can
somebody enlighten me??
No, unless you post a complete code sample. The error you get has nothing to
do with the last line, what we need is what you are doing with outputReader
after the WaitForExit.

Willy.

Nov 6 '07 #2

P: n/a
I have tried doing UseShellExecute=false also. Still the problem
persists. The code throws this Exception:

{"Cannot create instance of 'Window1' defined in assembly 'TrialMon,
Version=1.0.2866.25665, Culture=neutral, PublicKeyToken=null'.
Exception has been thrown by the target of an invocation. Error in
markup file 'Window1.xaml' Line 1 Position 9."}

Can someone tell me how this is related to starting a process.

Nov 6 '07 #3

P: n/a
I solved the problem by calling the process in a separate thread.
There seems to be no solution for this problem when the application is
single threaded.

Thanks Willy for your help,
Sundar

Nov 6 '07 #4

P: n/a
"sundarvenkata" <su***********@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
>I solved the problem by calling the process in a separate thread.
There seems to be no solution for this problem when the application is
single threaded.

Thanks Willy for your help,
Sundar

Your problem is due to the fact that you call it in the Window constructor
and, or your code throws an exception, or takes too long to return to the
constructor.
Anyway, something similar works for me (executing netstat -a), all you
should do is move the code to a handler and wrap it in a try/catch block. If
you have to wait for the process to exit, you can run it from another
thread.
Willy.

Nov 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.