• Home
  • About
  • Music
  • Photography
  • Software
 

Console input stream empty or not?

posted on Jul 20, 2008 by Gus  

This is making me grumpy so I’m going to share and see if this eventually (assuming I find a solution) serves as a place where others don’t run into what I’ve been struggling with. It would seem to be a simple problem but I haven’t been able to figure it out in a way that feels right (i.e., I have it “working” but just not convinced it’s done “right.”).

Problem:

Detect whether or not there are any characters in the input stream to a console application when it starts up. I.e., has some data been piped to it or not.

My current solution:

bool IsThereSomethingThere()
{
    try
    {
        return Console.KeyAvailable;
    }
    catch (InvalidOperationException)
    {
        // There is something in the input stream
    }

    return true;
}

How does it work?

Console.KeyAvailable throws an InvalidOperationException if the standard input is redirected to something other than the keyboard. In the cases where output from another command/application is piped to the console app it will throw the exception. If nothing has been piped to it, it happily returns false and moves on just fine.

My dilemma

I’m having a hard time believing the only way to do this is by expecting an exception–that never sounds good to me. Problem is I’ve tried a few other ways that would seem to have had a good chance at working (such as the various other Console methods available like Peek(), Read*(), etc.) but none work. Peek, for example, should return a -1 when there are no more characters in the buffer but it’s actually blocking for me (i.e., it’s waiting for input instead of just coming back to me with a -1).

I’m sure I’m missing something simple so I ended up doing a few searches and found a few that were having similar problems but no answers. At this point, I guess I’ll sleep on it and see how it goes tomorrow but if anyone knows better I’d certainly appreciate a clue.

digg this

add to delicious

add to technorati

stumble it!

No Comment

ezClip v1.20 — Real piping support

posted on Jul 20, 2008 by Gus  

I was thinking today (rare occasion) and realized I could also just add support for actually piping data into ezclip.exe directly. I went ahead and coded it up and there’s a new version of ezClip available now that supports it. I think this method is how I’ll be using it more often than the version of a similar feature I added yesterday.

Assuming ezclip.exe lives somewhere in your %path% environment variable, one can now type something like ‘dir /s /b | ezclip’ and the output of the dir command will directly be copied to the clipboard.

You can get the latest version from the ezClip page as usual.

digg this

add to delicious

add to technorati

stumble it!

No Comment

ezClip v1.15 — Pipe to clipboard support (of sorts)

posted on Jul 19, 2008 by Gus  

Danny had a good idea on a FriendFeed thread yesterday that I decided to add to ezClip today. His idea was actually having the Windows clipboard available as a device that one can pipe stuff to. The ‘output’ feature I just added sort of comes close to that and I thought it would be useful.

Basically, it saves me from the typical pattern I follow when needing to get the output of something I run on the command-line into an email (e.g., pipe it to a file, open it in notepad, ctrl-a to select all, ctrl-c to copy to clipboard, etc.). Now, I can just type this instead and get the same results: ‘ezclip o dir /b /s’ and happily ctrl-v away.

The latest version can be downloaded from the ezClip page here.

digg this

add to delicious

add to technorati

stumble it!

3 Comments

« Older Entries

Search

Recent Posts

  • Console input stream empty or not?
  • ezClip v1.20 — Real piping support
  • ezClip v1.15 — Pipe to clipboard support (of sorts)
  • Goodbye Netflix Profiles?
  • ezClip v1.1 — Some useful improvements
  • A great start to the day…
  • NameTag comes home…
  • TAB: Glen Hansard - Leave
  • The Swell Season, Live at The Moore (4.30.08)
  • My backup story…
    Proposal Rock FireworksCold FunNeskowin BeachAround the bendThe RockShorelineHanging out...Komodo lookbackDragonly slobberA jawlineFeeling a little left out...Fun at the gym...Rockies #1Rockies #2Rockies #3

Popular Tags

acura bluetooth chords download downloads falling slowly free glen hansard guitar handsfreelink internet explorer mac macbook pro marketa irglova microsoft mobile motorola q movie music netflix once outlook photography search software speech swell season tablature tabs the frames TickTalker tl tools update updates utilities verizon video vista windows windows live windows mobile windows mobile 6 wm6 wordpress

Recent Entries

  • Console input stream empty or not?
  • ezClip v1.20 — Real piping support
  • ezClip v1.15 — Pipe to clipboard support (of sorts)
  • Goodbye Netflix Profiles?
  • ezClip v1.1 — Some useful improvements
  • A great start to the day…
  • NameTag comes home…
  • TAB: Glen Hansard - Leave
  • The Swell Season, Live at The Moore (4.30.08)
  • My backup story…

Recent Comments

  • Gus in ezClip v1.15 -- Pipe to clipboard s…
  • danny in ezClip v1.15 -- Pipe to clipboard s…
  • aBlogByGus : ez… in ezClip v1.15 -- Pipe to clipboard s…
  • aBlogByGus : ez… in ezClip
  • Thom Blake in Goodbye Netflix Profiles?
  • aBlogByGus : ez… in ezClip
  • hidden sound se… in ccDismiss
  • Gus in TAB: Glen Hansard - Leave
  • brimston3 in TAB: Glen Hansard - Leave
  • Andy in TAB: The Frames (Glen Hansard) - Fa…

Most Comments

  • TAB: The Frames (Glen Hansard) - Falling Slowly (24)
  • The Motorola Q rocks! (17)
  • Frustration Maximus (16)
  • NameTray and NameTag Software (9)
  • Media Player Frustration (7)
  • My backup story... (7)
  • RightSideUp (6)
  • TAB: Glen Hansard - Say It To Me Now (6)
  • Motorola Q update seems to fix all issues I had with Acura TL's Handsfree Link (5)
  • TickTalker (5)

Network Links

  • My Old Band
  • Work Blog - My work blog on MSDN

Popular Entries

  • you must install the popular plugin by alex king for this section to work

Who is writing this blog?

author A dad, a husband, a developer, an average guitarist, an amateur photographer, and a pretty bad golfer.
©2005-2007 Gus Perez

Theme by Lewis Hamilton Fan Site & Broadband TV
Valid XHTML and Valid CSS |

Archive/Sitemap