Click here to Skip to main content
12,065,888 members (28,183 online)

PIEBALDconsult - Professional Profile





Summary

    Blog RSS
24,847
Author
68,549
Authority
149,418
Debator
782
Editor
667
Enquirer
31,638
Organiser
9,503
Participant
BSCS 1992 Wentworth Institute of Technology

Originally from the Boston (MA) area. Lived in SoCal for a while. Now in the Phoenix (AZ) area.

OpenVMS enthusiast, ISO 8601 evangelist, photographer, opinionated SOB, acknowledged pedant and contrarian

---------------

"Using fewer technologies is better than using more." -- Rico Mariani

"Good code is its own best documentation. As you’re about to add a comment, ask yourself, ‘How can I improve the code so that this comment isn’t needed?’" -- Steve McConnell

"Every time you write a comment, you should grimace and feel the failure of your ability of expression." -- Unknown

"If you need help knowing what to think, let me know and I'll tell you." -- Jeffrey Snover [MSFT]

"Typing is no substitute for thinking." -- R.W. Hamming

"I find it appalling that you can become a programmer with less training than it takes to become a plumber." -- Bjarne Stroustrup

ZagNut’s Law: Arrogance is inversely proportional to ability.

"Well blow me sideways with a plastic marionette. I've just learned something new - and if I could award you a 100 for that post I would. Way to go you keyboard lovegod you." -- Pete O'Hanlon

"linq'ish" sounds like "inept" in German -- Andreas Gieriet

"Things would be different if I ran the zoo." -- Dr. Seuss

"Wrong is evil, and it must be defeated." –- Jeff Ello

"A good designer must rely on experience, on precise, logical thinking, and on pedantic exactness." -- Nigel Shaw

“It’s always easier to do it the hard way.” -- Blackhart

“If Unix wasn’t so bad that you can’t give it away, Bill Gates would never have succeeded in selling Windows.” -- Blackhart

"Omit needless local variables." -- Strunk... had he taught programming
  • 23 May 2014: Best Database Article of April 2014 - Second Prize
  • 31 Dec 2009: CodeProject MVP 2010

  
Articles 40 (Legend)
Tech Blogs 0
Messages 24,130 (Master)
Q&A Questions 7
Q&A Answers 615
Tips/Tricks 40
Reference 0
Comments 3,001

Groups

Below is the list of groups in which the member is participating

Tosche Station
Tosche Station
United States United States
"But I was going into Tosche Station to pick up some power converters!"
"You can waste time with your friends when your chores are done."
―Luke Skywalker and Owen Lars


Like Tosche Station on Tatooine, this is a place for desert-dwellers to waste time with their friends; even if your chores aren't done. If you pick up a power converter, so much the better.

This group is intended as a meeting place for Code Projectors in Arizona and New Mexico. I suppose that Utah and Nevada are close enough. El Paso and El Centro are pushing it, but I'd be remiss to leave you out.

-- Your host
PIEBALDconsult
Phoenix, AZ
Group type: Social Group
This member has Group Status: Administrator, Manager, Author, Member

members

CodeProject Beta Testers
United States United States
No Biography provided
Group type: Collaborative Group
This member has Group Status: Member

members

Reputation

For more information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege, and the given member types also gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilverAdmin
Store personal files in your account areaplatinumplatinumSitebuilder, Subeditor, Supporter, Editor, Staff
Have live hyperlinks in your biographybronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Edit a Question in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Edit an Answer in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Delete a Question in Q&AYesSubeditor, Protector, Editor, Admin
Delete an Answer in Q&AYesSubeditor, Protector, Editor, Admin
Report an ArticlesilversilversilversilverSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubeditor, Mentor, Protector, Editor, Staff, Admin
Edit other members' articlesSubeditor, Protector, Editor, Admin
Create an article without requiring moderationplatinumSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending QuestionProtector, Admin
Approve/Disapprove a pending AnswerProtector, Admin
Report a forum messagesilversilverbronzeProtector, Editor, Admin
Approve/Disapprove a pending Forum MessageProtector, Admin
Create a new tagsilversilversilversilverAdmin
Modify a tagsilversilversilversilverAdmin

Actions with a green tick can be performed by this member.


 
GeneralOn the word PIEBALD Pin
PIEBALDconsult19-Nov-14 7:03
protectorPIEBALDconsult19-Nov-14 7:03 
GeneralRe: On the word PIEBALD Pin
DaveAuld19-Nov-14 7:14
protectorDaveAuld19-Nov-14 7:14 
GeneralRe: On the word PIEBALD Pin
H.Brydon19-Nov-14 7:59
mvpH.Brydon19-Nov-14 7:59 
GeneralA compendium of "Number to Word" Articles and Tips Pin
PIEBALDconsult8-Aug-14 9:25
memberPIEBALDconsult8-Aug-14 9:25 
GeneralOn why to use a DataReader Pin
PIEBALDconsult23-Feb-11 3:07
memberPIEBALDconsult23-Feb-11 3:07 
GeneralAutomatically closing a nag-ware window Pin
PIEBALDconsult26-Jan-11 15:54
memberPIEBALDconsult26-Jan-11 15:54 
GeneralPIEBALD's general rule for code formatting Pin
PIEBALDconsult19-Jan-11 19:24
memberPIEBALDconsult19-Jan-11 19:24 
GeneralOn producing a hash string Pin
PIEBALDconsult2-Mar-10 11:13
mvpPIEBALDconsult2-Mar-10 11:13 
GeneralOn determining whether or not a console application's input or output is piped/redirected Pin
PIEBALDconsult2-Mar-10 10:33
mvpPIEBALDconsult2-Mar-10 10:33 
(I don't feel that this code is enough to warrant a full article.)

Many times when writing a command-line/console application or utility, I desire different behavior when the input is a pipe or the output is redirected. For instance:

0) I may not be able to prompt for input or confirmation.
1) I may want to make the output more (or less) verbose.

It appears that .net does not make detecting such redirection easy. When I first butted up against this wall I searched and found an article by Dr. Gui which addressed using the Windows API function PeekConsoleInput to detect whether or not console input is a pipe. More recent searches have not turned up this article or any other.

Here then is my take on Dr. Gui's technique, with the ability to detect redirected output added:

# region Heading
 
/**************************************************************************************************************/
/*                                                                                                            */
/*  LibApi.IsPipe.cs                                                                                          */
/*                                                                                                            */
/*  IsPipe routine                                                                                            */
/*                                                                                                            */
/*  This is free code, use it as you require. If you modify it please use your own namespace.                 */
/*                                                                                                            */
/*  If you like it or have suggestions for improvements please let me know at: PIEBALDconsult@aol.com         */
/*                                                                                                            */
/*  Modification history:                                                                                     */
/*  2003-11-24          Sir John E. Boucher     Added IsPipe -- With thanks to Dr. Gui                        */
/*                                                                                                            */
/**************************************************************************************************************/
 
# endregion
 
namespace PIEBALD.Lib
{
    public static partial class LibApi
    {
        /**
        <summary>
            Standard I/O device numbers
        </summary>
        */
        public enum StdPort : uint
        {
            /**
            <summary>
                Standard input port
            </summary>
            */
            In  = unchecked ( (uint) -10 ) 
        ,
            /**
            <summary>
                Standard output port
            </summary>
            */
            Out = unchecked ( (uint) -11 ) 
        ,
            /**
            <summary>
                Standard error port
            </summary>
            */
            Err = unchecked ( (uint) -12 )
        } ;
 
/**************************************************************************************************************/
 
        [System.Runtime.InteropServices.DllImportAttribute 
        ( 
            "Kernel32" 
        , 
            SetLastError=true 
        , 
            EntryPoint="GetStdHandle" 
        )]
        private static extern System.IntPtr
        API_GetStdHandle
        (
            StdPort nStdHandle
        ) ;
 
        [System.Runtime.InteropServices.DllImportAttribute 
        ( 
            "Kernel32" 
        , 
            SetLastError=true
        , 
            EntryPoint="PeekConsoleInput" 
        )]
        private static extern bool
        API_PeekConsoleInput
        (
            System.IntPtr hConsoleInput        
        ,  
            System.IntPtr lpBuffer             
        , 
            uint          nLength              
        , 
            out uint      lpNumberOfEventsRead
        ) ;
 
        [System.Runtime.InteropServices.DllImportAttribute 
        ( 
            "Kernel32" 
        , 
            SetLastError=true
        , 
            EntryPoint="WriteConsole" 
        )]
        private static extern bool
        API_WriteConsole
        (
            System.IntPtr hConsoleOutput        
        ,  
            System.IntPtr lpBuffer             
        , 
            uint          nNumberOfCharsToWrite
        ,
            out uint      lpNumberOfCharsWritten               
        , 
            System.IntPtr lpReserved
        ) ;
 
        /**
        <summary>
            Test a standard I/O (console) port to determine whether or not it is a pipe (redirected)
        </summary>
        <remarks>
            From a post by Dr. Gui
        </remarks>
        <param name="Port">
            The port to test for pipeness
        </param>
        <returns>
            Whether or not the port appears to be a pipe
        </returns>
        */
        public static bool
        IsPipe
        (
            StdPort Port
        )
        {
            bool result = false ;
            uint junk   ;
 
            switch ( Port )
            {
                case StdPort.In :
                {
                    result = !API_PeekConsoleInput
                    (
                        API_GetStdHandle ( Port ) 
                    ,
                        System.IntPtr.Zero                  
                    ,
                        0                            
                    ,
                        out junk
                    ) ;
 
                    break ;
                }
 
                case StdPort.Out :
                case StdPort.Err :
                {
                    result = !API_WriteConsole
                    (
                        API_GetStdHandle ( Port ) 
                    ,
                        System.IntPtr.Zero                  
                    ,
                        0                            
                    ,
                        out junk
                    ,
                        System.IntPtr.Zero                  
                    ) ;
 
                    break ;
                }
            }
 
            return ( result ) ;
        }
 
/**************************************************************************************************************/
    }
}

GeneralOn compiling at the command line Pin
PIEBALDconsult20-Aug-09 18:32
memberPIEBALDconsult20-Aug-09 18:32 
GeneralOn System.Environment.NewLine Pin
PIEBALDconsult19-Aug-09 5:51
memberPIEBALDconsult19-Aug-09 5:51 
GeneralRe: On System.Environment.NewLine Pin
aspdotnetdev19-Aug-09 22:34
memberaspdotnetdev19-Aug-09 22:34 
GeneralRe: On System.Environment.NewLine Pin
PIEBALDconsult20-Aug-09 8:47
memberPIEBALDconsult20-Aug-09 8:47 
GeneralOn the use of terms related to classes and interfaces Pin
PIEBALDconsult18-Aug-09 11:08
memberPIEBALDconsult18-Aug-09 11:08 
GeneralRe: On the use of terms related to classes and interfaces Pin
aspdotnetdev27-Jan-10 15:33
memberaspdotnetdev27-Jan-10 15:33 
GeneralOn clearing a StringBuilder Pin
PIEBALDconsult25-Feb-09 17:53
memberPIEBALDconsult25-Feb-09 17:53 
GeneralOn overloading the increment and decrement operators Pin
PIEBALDconsult25-Feb-09 10:45
memberPIEBALDconsult25-Feb-09 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160207.1 | Last Updated 7 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid