Console app (Debug)- how to redirect standard input/output?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cohagan

    Console app (Debug)- how to redirect standard input/output?

    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 line"
    argument property, but no joy.

    So, have I missed something? Is there a way to simulate redirection from
    within the IDE for a Console app?

    Thanks in advance,
    Bill


  • Bret Mulvey

    #2
    Re: Console app (Debug)- how to redirect standard input/output?

    Have you tried Console.SetIn() and Console.SetOut( )? The ">" redirection
    syntax is handled by the command-line interpreter and the IDE doesn't
    simulate that. It just treats it as a regular string and the redirection
    command gets passed as a string argument, which it looks like you've
    discovered.


    "Bill Cohagan" <bill@teraXNOSP AMXquest.com> wrote in message
    news:#BYk0SShDH A.2504@TK2MSFTN GP09.phx.gbl...[color=blue]
    > 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[/color]
    want[color=blue]
    > to support the "<" and ">" redirection syntax. The obvious way to do this[/color]
    is[color=blue]
    > 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 line"
    > argument property, but no joy.
    >
    > So, have I missed something? Is there a way to simulate redirection from
    > within the IDE for a Console app?
    >
    > Thanks in advance,
    > Bill
    >
    >[/color]


    Comment

    • Bill Cohagan

      #3
      Re: Console app (Debug)- how to redirect standard input/output?

      Bret-
      Yes, I've tried SetIn and SetOut, but that means I have to execute
      different code in the IDE than I do "in real life", not a very robust
      situation. As it turns out I'm having major problems with just using
      Console.In in the EXE; i.e., not in the IDE. I'm building a validating XML
      reader around that input stream and I'm getting an error complaining that
      the object doesn't support a write (?).

      Thanks for the response,
      Bill

      "Bret Mulvey" <bretm@microsof t.nospam0000.co m> wrote in message
      news:Jkldb.6001 84$Ho3.117213@s ccrnsc03...[color=blue]
      > Have you tried Console.SetIn() and Console.SetOut( )? The ">" redirection
      > syntax is handled by the command-line interpreter and the IDE doesn't
      > simulate that. It just treats it as a regular string and the redirection
      > command gets passed as a string argument, which it looks like you've
      > discovered.
      >
      >
      > "Bill Cohagan" <bill@teraXNOSP AMXquest.com> wrote in message
      > news:#BYk0SShDH A.2504@TK2MSFTN GP09.phx.gbl...[color=green]
      > > 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[/color]
      > want[color=green]
      > > to support the "<" and ">" redirection syntax. The obvious way to do[/color][/color]
      this[color=blue]
      > is[color=green]
      > > 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[/color][/color]
      edited[color=blue][color=green]
      > > the project properties and added the necessary text to the "command[/color][/color]
      line"[color=blue][color=green]
      > > argument property, but no joy.
      > >
      > > So, have I missed something? Is there a way to simulate redirection from
      > > within the IDE for a Console app?
      > >
      > > Thanks in advance,
      > > Bill
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Peter Huang [MSFT]

        #4
        Re: Console app (Debug)- how to redirect standard input/output?

        Hi Bill,

        Can you check my replied to your another post in this queue?
        Subject: Write error on Read() ??

        Regards,
        Peter Huang
        Microsoft Online Partner Support
        Get Secure! www.microsoft.com/security
        This posting is provided "as is" with no warranties and confers no rights.

        --------------------[color=blue]
        >From: "Bill Cohagan" <bill@teraXNOSP AMXquest.com>
        >References: <#BYk0SShDHA.25 04@TK2MSFTNGP09 .phx.gbl>[/color]
        <Jkldb.600184$H o3.117213@sccrn sc03>[color=blue]
        >Subject: Re: Console app (Debug)- how to redirect standard input/output?
        >Date: Sat, 27 Sep 2003 15:19:22 -0500
        >Lines: 46
        >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: <ugWzjSThDHA.32 08@TK2MSFTNGP11 .phx.gbl>
        >Newsgroups:[/color]
        microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.lang uages.csharp[color=blue]
        >NNTP-Posting-Host: cs24313-53.austin.rr.co m 24.243.13.53
        >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
        >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1877 16[/color]
        microsoft.publi c.dotnet.genera l:110126[color=blue]
        >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
        >
        >Bret-
        > Yes, I've tried SetIn and SetOut, but that means I have to execute
        >different code in the IDE than I do "in real life", not a very robust
        >situation. As it turns out I'm having major problems with just using
        >Console.In in the EXE; i.e., not in the IDE. I'm building a validating XML
        >reader around that input stream and I'm getting an error complaining that
        >the object doesn't support a write (?).
        >
        >Thanks for the response,
        > Bill
        >
        >"Bret Mulvey" <bretm@microsof t.nospam0000.co m> wrote in message
        >news:Jkldb.600 184$Ho3.117213@ sccrnsc03...[color=green]
        >> Have you tried Console.SetIn() and Console.SetOut( )? The ">" redirection
        >> syntax is handled by the command-line interpreter and the IDE doesn't
        >> simulate that. It just treats it as a regular string and the redirection
        >> command gets passed as a string argument, which it looks like you've
        >> discovered.
        >>
        >>
        >> "Bill Cohagan" <bill@teraXNOSP AMXquest.com> wrote in message
        >> news:#BYk0SShDH A.2504@TK2MSFTN GP09.phx.gbl...[color=darkred]
        >> > 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[/color]
        >> want[color=darkred]
        >> > to support the "<" and ">" redirection syntax. The obvious way to do[/color][/color]
        >this[color=green]
        >> is[color=darkred]
        >> > 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[/color][/color]
        >edited[color=green][color=darkred]
        >> > the project properties and added the necessary text to the "command[/color][/color]
        >line"[color=green][color=darkred]
        >> > argument property, but no joy.
        >> >
        >> > So, have I missed something? Is there a way to simulate redirection[/color][/color][/color]
        from[color=blue][color=green][color=darkred]
        >> > within the IDE for a Console app?
        >> >
        >> > Thanks in advance,
        >> > Bill
        >> >
        >> >[/color]
        >>
        >>[/color]
        >
        >
        >[/color]

        Comment

        Working...