473,763 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write error on Read() ??

I'm writing a console app in c# and am encountering a strange problem. I'm
trying to use redirection of the standard input stream to read input from a
(xml) file. The following code snippet is from this app:
=============== =============== =
static void Main(string[] args)
{
if (args.Length > 0) Console.SetIn(n ew StreamReader(ar gs[0]));
//executes if I don't use the "<", ">" redirection syntax when invoking

XmlTextReader xmlin = new XmlTextReader(C onsole.In);
xmlin.Whitespac eHandling = WhitespaceHandl ing.None;

if (args.Length > 1) Console.SetOut( new
StreamWriter(ar gs[1]));//executes if I don't use the "<", ">" redirection
syntax when invoking

XmlTextWriter xmlw = new XmlTextWriter(C onsole.Out);
string SchemaResource = "DBDumper.DumpS pec0.xsd";
XmlValidatingRe ader xmlvr = new XmlValidatingRe ader(xmlin);
Assembly a = Assembly.GetExe cutingAssembly( );
Debug.Assert (a.GetManifestR esourceInfo(Sch emaResource) != null);
XmlTextReader xsdreader = new XmlTextReader(n ew
StreamReader(a. GetManifestReso urceStream(Sche maResource)));
xmlvr.Schemas.A dd(null, xsdreader);
try
{
xmlvr.Read();
....
=============== ==============
So, assuming my app's executable is foo.exe, things work fine if I type in

foo input.xml output.xml

Also,
foo input.xml > output.xml

works fine. But, if I type in:

foo < input.xml > output.xml

I get an error on the xmlvr.Read() in the last line above, complaining that
the stream does not support a Write!!

Can anyone give me help on this? I've stared at it now for a while and don't
see the problem.

Thanks in advance,
Bill
Nov 15 '05 #1
3 2755

Hi Bill,

If you want to get " foo < input.xml > output.xml" work, you should
parse the command line parameter for multi-parameters.

I think you can use string.split() method to parse the command string into
an array of string, then you can apply your command line program logic.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Bill Cohagan" <bi**@teraXNOSP AMXquest.com>
| Subject: Write error on Read() ??
| Date: Sat, 27 Sep 2003 16:24:02 -0500
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#x************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.lang uages.csharp
| NNTP-Posting-Host: cs24313-53.austin.rr.co m 24.243.13.53
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl
microsoft.publi c.dotnet.langua ges.csharp:1877 25
microsoft.publi c.dotnet.genera l:110132
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| I'm writing a console app in c# and am encountering a strange problem. I'm
| trying to use redirection of the standard input stream to read input from
a
| (xml) file. The following code snippet is from this app:
| =============== =============== =
| static void Main(string[] args)
| {
| if (args.Length > 0) Console.SetIn(n ew StreamReader(ar gs[0]));
| //executes if I don't use the "<", ">" redirection syntax when invoking
|
| XmlTextReader xmlin = new XmlTextReader(C onsole.In);
| xmlin.Whitespac eHandling = WhitespaceHandl ing.None;
|
| if (args.Length > 1) Console.SetOut( new
| StreamWriter(ar gs[1]));//executes if I don't use the "<", ">" redirection
| syntax when invoking
|
| XmlTextWriter xmlw = new XmlTextWriter(C onsole.Out);
| string SchemaResource = "DBDumper.DumpS pec0.xsd";
| XmlValidatingRe ader xmlvr = new XmlValidatingRe ader(xmlin);
| Assembly a = Assembly.GetExe cutingAssembly( );
| Debug.Assert (a.GetManifestR esourceInfo(Sch emaResource) != null);
| XmlTextReader xsdreader = new XmlTextReader(n ew
| StreamReader(a. GetManifestReso urceStream(Sche maResource)));
| xmlvr.Schemas.A dd(null, xsdreader);
| try
| {
| xmlvr.Read();
| ....
| =============== ==============
| So, assuming my app's executable is foo.exe, things work fine if I type in
|
| foo input.xml output.xml
|
| Also,
| foo input.xml > output.xml
|
| works fine. But, if I type in:
|
| foo < input.xml > output.xml
|
| I get an error on the xmlvr.Read() in the last line above, complaining
that
| the stream does not support a Write!!
|
| Can anyone give me help on this? I've stared at it now for a while and
don't
| see the problem.
|
| Thanks in advance,
| Bill
|
|
|

Nov 15 '05 #2
Jeffrey-
Well, that's a shock! I would have thought that the framework would
provide a "transparen t" way of implementing redirection of standard in,
standard out, and standard error. In particular, if I hardwire the logic
myself by parsing the command line, then my application will not work if
invoked by another application that binds these standard input/output
streams. To use a built in command as an example, I can (at a command
prompt) do:

dir foo.* > dirlist.txt

and get the result of the directory listing written to the dirlist.txt file.
I can also invoke the "dir" command from another app by using the
"startinfo" property of a process object. (See MSDN article [305994 - HOWTO:
Write a Wrapper for a Command-Line Tool with Visual C# .NET]. This is
precisely the functionality I want to have for my own application.

The approach you suggest would not support this since the code would expect
a command line containing the file names and wouldn't react as expected to
having a calling process rebind these streams. Surely MS didn't intend that
this functionality not be possible in user written console apps!!

I would also point out that my code appears to work fine for the output
stream; i.e., the STDOUT stream is "automatica lly" rebound to the designated
file. It is just the input stream that is a problem -- and my guess is that
the problem is somehow associated with trying to use it as an xmltextreader
(rather than just a textreader).

I'd appreciate it if you'd research this a bit further and let me know if
there's a (framework?) bug here or point me to some docs that explain why
this code doesn't work. In any case I do appreciate your quick response.

If you'd like I can simplify the code snippet a bit by eliminating the
validation portion; i.e., just use the constructed xmltextreader rather than
the validating reader when inovking the Read() method. You should still see
the error. To test this of course you'd need to create a (trivial) XML input
file to use.

Regards,
Bill

"Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> wrote in message
news:YU******** ******@cpmsftng xa06.phx.gbl...

Hi Bill,

If you want to get " foo < input.xml > output.xml" work, you should
parse the command line parameter for multi-parameters.

I think you can use string.split() method to parse the command string into
an array of string, then you can apply your command line program logic.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Bill Cohagan" <bi**@teraXNOSP AMXquest.com>
| Subject: Write error on Read() ??
| Date: Sat, 27 Sep 2003 16:24:02 -0500
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#x************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.lang uages.csharp
| NNTP-Posting-Host: cs24313-53.austin.rr.co m 24.243.13.53
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl
microsoft.publi c.dotnet.langua ges.csharp:1877 25
microsoft.publi c.dotnet.genera l:110132
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| I'm writing a console app in c# and am encountering a strange problem. I'm | trying to use redirection of the standard input stream to read input from a
| (xml) file. The following code snippet is from this app:
| =============== =============== =
| static void Main(string[] args)
| {
| if (args.Length > 0) Console.SetIn(n ew StreamReader(ar gs[0]));
| //executes if I don't use the "<", ">" redirection syntax when invoking
|
| XmlTextReader xmlin = new XmlTextReader(C onsole.In);
| xmlin.Whitespac eHandling = WhitespaceHandl ing.None;
|
| if (args.Length > 1) Console.SetOut( new
| StreamWriter(ar gs[1]));//executes if I don't use the "<", ">" redirection | syntax when invoking
|
| XmlTextWriter xmlw = new XmlTextWriter(C onsole.Out);
| string SchemaResource = "DBDumper.DumpS pec0.xsd";
| XmlValidatingRe ader xmlvr = new XmlValidatingRe ader(xmlin);
| Assembly a = Assembly.GetExe cutingAssembly( );
| Debug.Assert (a.GetManifestR esourceInfo(Sch emaResource) != null);
| XmlTextReader xsdreader = new XmlTextReader(n ew
| StreamReader(a. GetManifestReso urceStream(Sche maResource)));
| xmlvr.Schemas.A dd(null, xsdreader);
| try
| {
| xmlvr.Read();
| ....
| =============== ==============
| So, assuming my app's executable is foo.exe, things work fine if I type in |
| foo input.xml output.xml
|
| Also,
| foo input.xml > output.xml
|
| works fine. But, if I type in:
|
| foo < input.xml > output.xml
|
| I get an error on the xmlvr.Read() in the last line above, complaining
that
| the stream does not support a Write!!
|
| Can anyone give me help on this? I've stared at it now for a while and
don't
| see the problem.
|
| Thanks in advance,
| Bill
|
|
|

Nov 15 '05 #3
Jeffrey-

I've figured out the problem. In my case the XML file in question was
written using UTF-8 encoding -- which apparently includes some binary
"chars" at the beginning of the file. If I remove those characters then my
use of Console.In to create an xmltextreader works as expected. So, the
problem was pilot error; although I think the "Write error on Read()" error
was certainly a misleading one!

Thanks again for the response -- though I believe the suggestion to parse
the command line was a red herring. :-)

Bill

"Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> wrote in message
news:YU******** ******@cpmsftng xa06.phx.gbl...

Hi Bill,

If you want to get " foo < input.xml > output.xml" work, you should
parse the command line parameter for multi-parameters.

I think you can use string.split() method to parse the command string into
an array of string, then you can apply your command line program logic.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Bill Cohagan" <bi**@teraXNOSP AMXquest.com>
| Subject: Write error on Read() ??
| Date: Sat, 27 Sep 2003 16:24:02 -0500
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#x************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.lang uages.csharp
| NNTP-Posting-Host: cs24313-53.austin.rr.co m 24.243.13.53
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl
microsoft.publi c.dotnet.langua ges.csharp:1877 25
microsoft.publi c.dotnet.genera l:110132
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| I'm writing a console app in c# and am encountering a strange problem. I'm | trying to use redirection of the standard input stream to read input from a
| (xml) file. The following code snippet is from this app:
| =============== =============== =
| static void Main(string[] args)
| {
| if (args.Length > 0) Console.SetIn(n ew StreamReader(ar gs[0]));
| //executes if I don't use the "<", ">" redirection syntax when invoking
|
| XmlTextReader xmlin = new XmlTextReader(C onsole.In);
| xmlin.Whitespac eHandling = WhitespaceHandl ing.None;
|
| if (args.Length > 1) Console.SetOut( new
| StreamWriter(ar gs[1]));//executes if I don't use the "<", ">" redirection | syntax when invoking
|
| XmlTextWriter xmlw = new XmlTextWriter(C onsole.Out);
| string SchemaResource = "DBDumper.DumpS pec0.xsd";
| XmlValidatingRe ader xmlvr = new XmlValidatingRe ader(xmlin);
| Assembly a = Assembly.GetExe cutingAssembly( );
| Debug.Assert (a.GetManifestR esourceInfo(Sch emaResource) != null);
| XmlTextReader xsdreader = new XmlTextReader(n ew
| StreamReader(a. GetManifestReso urceStream(Sche maResource)));
| xmlvr.Schemas.A dd(null, xsdreader);
| try
| {
| xmlvr.Read();
| ....
| =============== ==============
| So, assuming my app's executable is foo.exe, things work fine if I type in |
| foo input.xml output.xml
|
| Also,
| foo input.xml > output.xml
|
| works fine. But, if I type in:
|
| foo < input.xml > output.xml
|
| I get an error on the xmlvr.Read() in the last line above, complaining
that
| the stream does not support a Write!!
|
| Can anyone give me help on this? I've stared at it now for a while and
don't
| see the problem.
|
| Thanks in advance,
| Bill
|
|
|

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2433
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from this app: =============================== static void Main(string args) { if (args.Length > 0) Console.SetIn(new StreamReader(args)); //executes if I don't use the "<", ">" redirection syntax when invoking XmlTextReader xmlin = new...
0
1052
by: Frederic Rentsch | last post by:
Hi all, Working with read and write operations on a file I stumbled on a complication when writes fail following a read to the end. 30L 'abcdefg' Traceback (most recent call last): File "<pyshell#62>", line 1, in -toplevel-
6
17241
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14055
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
8282
by: eholz1 | last post by:
Hello PHP Group, I am having trouble setting permissions correctly so that the magickwand api (php 5.2) can read and write images. I usually read a file from one directory, create a magickwand resource from that file, and transform the image, and save the new image with a new name to a different directory. I have seen that my file and folder permissions when set incorrectly,
2
20743
by: adypoly | last post by:
Hi guys... I am having a typical problem in using one of the native dll in C# I'll explain what am trying to do, I've a dll written in C language which i am trying to include in my C# project, the solutions builds fine but once i try to run the program it gives an exception as "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" I am passing two integer pointer variables as the...
24
4456
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone help out a newbie? #include <stdio.h> #include <ctype.h> #include <string.h>
65
5093
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
3
6948
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or write protected memory. this is often an indication that other memory is corrupt.... " These are all the platform info : Visual Studio 2005 (VB.NET) and ASP.NET 2.0.
0
9563
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
9386
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
9998
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
9938
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,...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.