473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

WPF and Standard Output redirection - Weird Error

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
4 2211
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Grzegorz | last post by:
Hello, I'm using eclipse with pydev plugin, I'm working on a program using wxpython . When I'm executing that application standard error output does not show in eclipse console window - wxpython...
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
4
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.