Windows Vista Forums

How do you comment long pipelines

  1. #1


    RickB Guest

    How do you comment long pipelines

    I have this function. It will probably wrap horribly but I hope you
    get the idea.



    How can I comment it?
    Nearly every spot I've tried to put any causes some kind of error.

    function Get-Hard_Output ([string]$fname)
    {(Execute-SQLcmd `
    "select process_log_key,batch_key
    from raser.dbo.process_log
    where process_name = 'Importer.BulkInsertFileToWorkTable2'
    and comment_desc like '%$($fname)%'" -q).tables.item(0).rows `
    |%{(Execute-SQLcmd `
    "select $($_.batch_key) as Batch_Key,
    Process_Log_Key, Comment_Desc
    from raser.dbo.process_log
    where process_log_key > $($_.process_log_key)
    and batch_key = $($_.batch_key)
    and event_type_key = 10
    and process_name = 'Exporter.WriteFileToWorkDir'
    and process_log_key <
    (select top 1 process_log_key from raser.dbo.process_log
    where process_log_key > $($_.process_log_key)
    and process_name in
    ('Importer.BulkInsertFileToWorkTable2','Engine.Run')
    order by process_log_key)
    order by process_log_key" -q).tables.item(0).rows}`
    |%{$t = $_;$t|select-object Batch_Key,Process_Log_Key,FileName `
    |%{$_.FileName = split-path ((($t.Comment_Desc).split())
    [1]) -leaf;$_}}`
    |%{$z = (Execute-SQLcmd `
    "select Comment_Desc
    from raser.dbo.process_log
    where process_log_key > $($_.process_log_key)
    and batch_key = $($_.batch_key)
    and event_type_key = 12
    and process_name = 'FileManager.ZipOutputFiles'
    and comment_desc like '%$($_.FileName)%'
    and process_log_key <
    (select top 1 process_log_key from
    raser.dbo.process_log
    where process_log_key > $($_.process_log_key)
    and process_name = 'Engine.Run'
    order by process_log_key)
    order by process_log_key" -q).tables.item(0).rows
    if ($z.count -gt 0)
    {$_.FileName = split-path ((($z.item(0).Comment_Desc).split())
    [3]) -leaf}
    $_}
    }

      My System SpecsSystem Spec

  2. #2


    Brandon Shell [MVP] Guest

    Re: How do you comment long pipelines

    You can use ` (backtick) to "effectively" escape the CRLF allowing you to
    span multiple lines for one command.

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    R> I have this function. It will probably wrap horribly but I hope you
    R> get the idea.
    R>
    R> How can I comment it?
    R> Nearly every spot I've tried to put any causes some kind of error.
    R> function Get-Hard_Output ([string]$fname)
    R> {(Execute-SQLcmd `
    R> "select process_log_key,batch_key
    R> from raser.dbo.process_log
    R> where process_name = 'Importer.BulkInsertFileToWorkTable2'
    R> and comment_desc like '%$($fname)%'" -q).tables.item(0).rows `
    R> |%{(Execute-SQLcmd `
    R> "select $($_.batch_key) as Batch_Key,
    R> Process_Log_Key, Comment_Desc
    R> from raser.dbo.process_log
    R> where process_log_key > $($_.process_log_key)
    R> and batch_key = $($_.batch_key)
    R> and event_type_key = 10
    R> and process_name = 'Exporter.WriteFileToWorkDir'
    R> and process_log_key <
    R> (select top 1 process_log_key from raser.dbo.process_log
    R> where process_log_key > $($_.process_log_key)
    R> and process_name in
    R> ('Importer.BulkInsertFileToWorkTable2','Engine.Run')
    R> order by process_log_key)
    R> order by process_log_key" -q).tables.item(0).rows}`
    R> |%{$t = $_;$t|select-object Batch_Key,Process_Log_Key,FileName `
    R> |%{$_.FileName = split-path
    R> ((($t.Comment_Desc).split())
    R> [1]) -leaf;$_}}`
    R> |%{$z = (Execute-SQLcmd `
    R> "select Comment_Desc
    R> from raser.dbo.process_log
    R> where process_log_key > $($_.process_log_key)
    R> and batch_key = $($_.batch_key)
    R> and event_type_key = 12
    R> and process_name = 'FileManager.ZipOutputFiles'
    R> and comment_desc like '%$($_.FileName)%'
    R> and process_log_key <
    R> (select top 1 process_log_key from
    R> raser.dbo.process_log
    R> where process_log_key > $($_.process_log_key)
    R> and process_name = 'Engine.Run'
    R> order by process_log_key)
    R> order by process_log_key" -q).tables.item(0).rows
    R> if ($z.count -gt 0)
    R> {$_.FileName = split-path
    R> ((($z.item(0).Comment_Desc).split())
    R> [3]) -leaf}
    R> $_}
    R> }



      My System SpecsSystem Spec

  3. #3
    EricPope's Avatar

    Newbie
    Join Date : Aug 2008
    Posts : 9
    Windows XP Pro
    Local Time: 07:33 AM


     

    Re: How do you comment long pipelines

    Commenting pipes should be pretty simple. PowerShell allows a line break after each pipeline marker. How about this example:

    "Eric" | #Its my name!
    %{ "Howdy $_" }

      My System SpecsSystem Spec

  4. #4


    RickB Guest

    Re: How do you comment long pipelines

    On Aug 7, 8:33*am, Brandon Shell [MVP] <a_bshell.m...@xxxxxx>
    wrote:

    > You can use ` (backtick) to "effectively" escape the CRLF allowing you to
    > span multiple lines for one command.
    >
    > Brandon Shell
    > ---------------
    > Blog:http://www.bsonposh.com/
    > PSH Scripts Project: *www.codeplex.com/psobject
    >
    > R> I have this function. *It will probably wrap horribly but I hope you
    > R> get the idea.
    > R>
    > R> How can I comment it?
    > R> Nearly every spot I've tried to put any causes some kind of error.
    > R> function Get-Hard_Output ([string]$fname)
    > R> {(Execute-SQLcmd `
    > R> "select process_log_key,batch_key
    > R> from raser.dbo.process_log
    > R> where process_name = 'Importer.BulkInsertFileToWorkTable2'
    > R> and comment_desc like '%$($fname)%'" -q).tables.item(0).rows `
    > R> |%{(Execute-SQLcmd `
    > R> "select $($_.batch_key) as Batch_Key,
    > R> Process_Log_Key, Comment_Desc
    > R> from raser.dbo.process_log
    > R> where process_log_key > $($_.process_log_key)
    > R> and batch_key = $($_.batch_key)
    > R> and event_type_key = 10
    > R> and process_name = 'Exporter.WriteFileToWorkDir'
    > R> and process_log_key <
    > R> (select top 1 process_log_key from raser.dbo.process_log
    > R> where process_log_key > $($_.process_log_key)
    > R> and process_name in
    > R> ('Importer.BulkInsertFileToWorkTable2','Engine.Run')
    > R> order by process_log_key)
    > R> order by process_log_key" *-q).tables.item(0).rows}`
    > R> |%{$t = $_;$t|select-object Batch_Key,Process_Log_Key,FileName `
    > R> |%{$_.FileName = split-path
    > R> ((($t.Comment_Desc).split())
    > R> [1]) -leaf;$_}}`
    > R> |%{$z = (Execute-SQLcmd `
    > R> "select Comment_Desc
    > R> from raser.dbo.process_log
    > R> where process_log_key > $($_.process_log_key)
    > R> and batch_key = $($_.batch_key)
    > R> and event_type_key = 12
    > R> and process_name = 'FileManager.ZipOutputFiles'
    > R> and comment_desc like '%$($_.FileName)%'
    > R> and process_log_key <
    > R> (select top 1 process_log_key from
    > R> raser.dbo.process_log
    > R> where process_log_key > $($_.process_log_key)
    > R> and process_name = 'Engine.Run'
    > R> order by process_log_key)
    > R> order by process_log_key" *-q).tables.item(0).rows
    > R> if ($z.count -gt 0)
    > R> {$_.FileName = split-path
    > R> ((($z.item(0).Comment_Desc).split())
    > R> [3]) -leaf}
    > R> $_}
    > R> }
    The Function I've pasted needs the backtick just to string such a long
    pipeline in a readable way.
    My problem is that a comment either causes an error or appears to be
    seen as a $null in the pipeline.
    Basically when I try to comment this it causes errors.

    Here is a smaller example of the bigger problem
    This works

    dir `
    c*

    This doesn't
    dir `
    # all files starting with c
    c*

      My System SpecsSystem Spec

  5. #5


    RickB Guest

    Re: How do you comment long pipelines

    On Aug 7, 1:09*pm, EricPope <gu...@xxxxxx-email.com> wrote:

    > Commenting pipes should be pretty simple. PowerShell allows a line break
    > after each pipeline marker. How about this example:
    >
    > "Eric" | #Its my name!
    > %{ "Howdy $_" }
    >
    > --
    > EricPope
    Thanks, yes, that does let me at least put some comments in.
    Eventually I'd like to comment certain individual arguments but
    I've got a whole lot more now than I had an hour ago.

      My System SpecsSystem Spec

  6. #6


    Brandon Shell [MVP] Guest

    Re: How do you comment long pipelines

    As long as the # follows the backtick you should be fine.

    btw... This going to be inefficient. I would use foreach(){} instead. Your
    readability will sky rocket and so will performance. Perhaps a good rule
    of thumb: If you have to use backtick to make it readable, it's not a one
    liner.


    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    R> On Aug 7, 8:33 am, Brandon Shell [MVP] <a_bshell.m...@xxxxxx>
    R> wrote:
    R>

    >> You can use ` (backtick) to "effectively" escape the CRLF allowing
    >> you to span multiple lines for one command.
    >>
    >> Brandon Shell
    >> ---------------
    >> Blog:http://www.bsonposh.com/
    >> PSH Scripts Project: www.codeplex.com/psobject
    >> R> I have this function. It will probably wrap horribly but I hope
    >> you
    >> R> get the idea.
    >> R>
    >> R> How can I comment it?
    >> R> Nearly every spot I've tried to put any causes some kind of error.
    >> R> function Get-Hard_Output ([string]$fname)
    >> R> {(Execute-SQLcmd `
    >> R> "select process_log_key,batch_key
    >> R> from raser.dbo.process_log
    >> R> where process_name = 'Importer.BulkInsertFileToWorkTable2'
    >> R> and comment_desc like '%$($fname)%'" -q).tables.item(0).rows `
    >> R> |%{(Execute-SQLcmd `
    >> R> "select $($_.batch_key) as Batch_Key,
    >> R> Process_Log_Key, Comment_Desc
    >> R> from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and batch_key = $($_.batch_key)
    >> R> and event_type_key = 10
    >> R> and process_name = 'Exporter.WriteFileToWorkDir'
    >> R> and process_log_key <
    >> R> (select top 1 process_log_key from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and process_name in
    >> R> ('Importer.BulkInsertFileToWorkTable2','Engine.Run')
    >> R> order by process_log_key)
    >> R> order by process_log_key" -q).tables.item(0).rows}`
    >> R> |%{$t = $_;$t|select-object Batch_Key,Process_Log_Key,FileName `
    >> R> |%{$_.FileName = split-path
    >> R> ((($t.Comment_Desc).split())
    >> R> [1]) -leaf;$_}}`
    >> R> |%{$z = (Execute-SQLcmd `
    >> R> "select Comment_Desc
    >> R> from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and batch_key = $($_.batch_key)
    >> R> and event_type_key = 12
    >> R> and process_name = 'FileManager.ZipOutputFiles'
    >> R> and comment_desc like '%$($_.FileName)%'
    >> R> and process_log_key <
    >> R> (select top 1 process_log_key from
    >> R> raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and process_name = 'Engine.Run'
    >> R> order by process_log_key)
    >> R> order by process_log_key" -q).tables.item(0).rows
    >> R> if ($z.count -gt 0)
    >> R> {$_.FileName = split-path
    >> R> ((($z.item(0).Comment_Desc).split())
    >> R> [3]) -leaf}
    >> R> $_}
    >> R> }
    R> The Function I've pasted needs the backtick just to string such a
    R> long
    R> pipeline in a readable way.
    R> My problem is that a comment either causes an error or appears to be
    R> seen as a $null in the pipeline.
    R> Basically when I try to comment this it causes errors.
    R> Here is a smaller example of the bigger problem
    R> This works
    R> dir `
    R> c*
    R> This doesn't
    R> dir `
    R> # all files starting with c
    R> c*



      My System SpecsSystem Spec

  7. #7


    Brandon Shell [MVP] Guest

    Re: How do you comment long pipelines

    As long as the # follows the backtick you should be fine.

    btw... This going to be inefficient. I would use foreach(){} instead. Your
    readability will sky rocket and so will performance. Perhaps a good rule
    of thumb: If you have to use backtick to make it readable, it’s not a one
    liner.

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    R> On Aug 7, 8:33 am, Brandon Shell [MVP] <a_bshell.m...@xxxxxx>
    R> wrote:
    R>

    >> You can use ` (backtick) to "effectively" escape the CRLF allowing
    >> you to span multiple lines for one command.
    >>
    >> Brandon Shell
    >> ---------------
    >> Blog:http://www.bsonposh.com/
    >> PSH Scripts Project: www.codeplex.com/psobject
    >> R> I have this function. It will probably wrap horribly but I hope
    >> you
    >> R> get the idea.
    >> R>
    >> R> How can I comment it?
    >> R> Nearly every spot I've tried to put any causes some kind of error.
    >> R> function Get-Hard_Output ([string]$fname)
    >> R> {(Execute-SQLcmd `
    >> R> "select process_log_key,batch_key
    >> R> from raser.dbo.process_log
    >> R> where process_name = 'Importer.BulkInsertFileToWorkTable2'
    >> R> and comment_desc like '%$($fname)%'" -q).tables.item(0).rows `
    >> R> |%{(Execute-SQLcmd `
    >> R> "select $($_.batch_key) as Batch_Key,
    >> R> Process_Log_Key, Comment_Desc
    >> R> from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and batch_key = $($_.batch_key)
    >> R> and event_type_key = 10
    >> R> and process_name = 'Exporter.WriteFileToWorkDir'
    >> R> and process_log_key <
    >> R> (select top 1 process_log_key from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and process_name in
    >> R> ('Importer.BulkInsertFileToWorkTable2','Engine.Run')
    >> R> order by process_log_key)
    >> R> order by process_log_key" -q).tables.item(0).rows}`
    >> R> |%{$t = $_;$t|select-object Batch_Key,Process_Log_Key,FileName `
    >> R> |%{$_.FileName = split-path
    >> R> ((($t.Comment_Desc).split())
    >> R> [1]) -leaf;$_}}`
    >> R> |%{$z = (Execute-SQLcmd `
    >> R> "select Comment_Desc
    >> R> from raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and batch_key = $($_.batch_key)
    >> R> and event_type_key = 12
    >> R> and process_name = 'FileManager.ZipOutputFiles'
    >> R> and comment_desc like '%$($_.FileName)%'
    >> R> and process_log_key <
    >> R> (select top 1 process_log_key from
    >> R> raser.dbo.process_log
    >> R> where process_log_key > $($_.process_log_key)
    >> R> and process_name = 'Engine.Run'
    >> R> order by process_log_key)
    >> R> order by process_log_key" -q).tables.item(0).rows
    >> R> if ($z.count -gt 0)
    >> R> {$_.FileName = split-path
    >> R> ((($z.item(0).Comment_Desc).split())
    >> R> [3]) -leaf}
    >> R> $_}
    >> R> }
    R> The Function I've pasted needs the backtick just to string such a
    R> long
    R> pipeline in a readable way.
    R> My problem is that a comment either causes an error or appears to be
    R> seen as a $null in the pipeline.
    R> Basically when I try to comment this it causes errors.
    R> Here is a smaller example of the bigger problem
    R> This works
    R> dir `
    R> c*
    R> This doesn't
    R> dir `
    R> # all files starting with c
    R> c*



      My System SpecsSystem Spec

  8. #8
    EricPope's Avatar

    Newbie
    Join Date : Aug 2008
    Posts : 9
    Windows XP Pro
    Local Time: 07:33 AM


     

    Re: How do you comment long pipelines

    Hi Brandon,
    The backtick, or grave as we call it where I'm from, escapes the newline character right? So how can you put a comment after it? Will you give an example of how you use graves with your comments?

      My System SpecsSystem Spec

  9. #9


    Brandon Shell [MVP] Guest

    Re: How do you comment long pipelines

    To be honest, I wouldn't do that. I just assumed it would work. Although
    I can see now why it wouldnt

    I will have to play
    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    E> Hi Brandon,
    E> The backtick, or grave as we call it where I'm from, escapes the
    E> newline character right? So how can you put a comment after it? Will
    E> you
    E> give an example of how you use graves with your comments?



      My System SpecsSystem Spec

  10. #10


    Keith Hill [MVP] Guest

    Re: How do you comment long pipelines

    "EricPope" <guest@xxxxxx-email.com> wrote in message
    news:73277291691ffa1ed41cc27eb892d82f@xxxxxx-gateway.com...

    >
    > Hi Brandon,
    > The backtick, or grave as we call it where I'm from, escapes the
    > newline character right? So how can you put a comment after it? Will you
    > give an example of how you use graves with your comments?
    >
    You can't. The backtick has to be the last character on a line. You can't
    even have whitespace after it.

    If you can end the command part of the line with an incomplete syntactic
    construct it will generally go into multiline mode. In those cases you can
    append comments onto the end of those lines.

    --
    Keith


      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
How do you comment long pipelines

Similar Threads
Thread Thread Starter Forum Replies Last Post
pipelines supported by PowerShell cmdlets Larry__Weiss PowerShell 0 10 Mar 2010
commenting multiline pipelines MichaelL PowerShell 10 18 Apr 2009
Colored Text and Pipelines NilVeritas PowerShell 2 15 Apr 2008
Fix for long, long, long deleting and copying of files? Hope Vista General 14 10 Feb 2008
Steppable Pipelines in Powershell 2.0 CTP Tao Ma PowerShell 6 13 Nov 2007