473,782 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnost ics.Process pfadminProc = new
System.Diagnost ics.Process();
pfadminProc.Sta rtInfo = new
ProcessStartInf o();
pfadminProc.Sta rtInfo.Redirect StandardInput = true;
pfadminProc.Sta rtInfo.Redirect StandardOutput = true;
pfadminProc.Sta rtInfo.Redirect StandardError = true;
pfadminProc.Sta rtInfo.FileName = "process";
pfadminProc.Sta rtInfo.Argument s = "arguments" ;
pfadminProc.Sta rt();
StreamReader outputReader =
pfadminProc.Sta ndardOutput;
pfadminProc.Wai tForExit();

When I try to execute the last line, I get an error saying that some
"Window1.xa ml" 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 2243
"sundarvenk ata" <su***********@ gmail.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.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.Diagnost ics.Process pfadminProc = new
System.Diagnost ics.Process();
pfadminProc.Sta rtInfo = new
ProcessStartInf o();
pfadminProc.Sta rtInfo.Redirect StandardInput = true;
pfadminProc.Sta rtInfo.Redirect StandardOutput = true;
pfadminProc.Sta rtInfo.Redirect StandardError = true;
pfadminProc.Sta rtInfo.FileName = "process";
pfadminProc.Sta rtInfo.Argument s = "arguments" ;
pfadminProc.Sta rt();
StreamReader outputReader =
pfadminProc.Sta ndardOutput;
pfadminProc.Wai tForExit();

When I try to execute the last line, I get an error saying that some
"Window1.xa ml" 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.286 6.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
"sundarvenk ata" <su***********@ gmail.comwrote in message
news:11******** **************@ o80g2000hse.goo glegroups.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
4042
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 seems to redirect standard output to some another window , and closes that window immediately, so I can't see any error messagess. Is there a way to redirect standard output to eclipse console ?
3
7787
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
4
8741
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
3
309
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7492
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.