Windows Vista Forums

..."format-table command conflicting with the default formatting"...
  1. #1


    James Guest

    ..."format-table command conflicting with the default formatting"...

    This is a script I wrote to give me the time until next year...

    [console]::title = "Next Year Count Down"

    $NextYearDate = get-date "1/1/2010"
    $NextYearDate - ([datetime]::now)

    while (1)
    {
    cls
    Write-Host "Time until Next Year: "
    write-host ""
    $NextYearDate - ([datetime]::now) | select days, hours, minutes, seconds |
    ft -autosize
    $NextYearDate - ([datetime]::now) | select totaldays, totalhours,
    totalminutes, totalseconds| ft -autosize
    sleep 1
    }



    It fails when run from a script, but succeeds when cut and pasted into the
    console. Ideas?


      My System SpecsSystem Spec

  2. #2


    Kiron Guest

    Re: ..."format-table command conflicting with the default formatting"...

    The problem is an outstream quirk that starts in this line:

    $NextYearDate - ([datetime]::now)

    When the output -in the form of a Format-List- is merged with Format-Table's output, the script breaks.
    To fix it pipe the output from that lne to Out-Default.

    # pipe the output to Out-Default
    $NextYearDate - ([datetime]::now) | Out-Default

    # or suppress it, since it's wiped by the cls statement anyway
    $NextYearDate - ([datetime]::now) | Out-Null

    --
    Kiron

      My System SpecsSystem Spec

  3. #3


    James Guest

    Re: ..."format-table command conflicting with the default formatting"...

    That's weird that it works when pasted to the powershell console, but not in
    the script, is it a bug? Anyway, the reason I added that, is because a blank
    line gets displayed before the time spans the first time the script runs
    (another bug?)
    "Kiron" <Kiron@xxxxxx> wrote in message
    news658F33C-F949-49BB-8D49-43C9FF8B4681@xxxxxx

    > The problem is an outstream quirk that starts in this line:
    >
    > $NextYearDate - ([datetime]::now)
    >
    > When the output -in the form of a Format-List- is merged with
    > Format-Table's output, the script breaks.
    > To fix it pipe the output from that lne to Out-Default.
    >
    > # pipe the output to Out-Default
    > $NextYearDate - ([datetime]::now) | Out-Default
    >
    > # or suppress it, since it's wiped by the cls statement anyway
    > $NextYearDate - ([datetime]::now) | Out-Null
    >
    > --
    > Kiron

      My System SpecsSystem Spec

  4. #4


    Kiron Guest

    Re: ..."format-table command conflicting with the default formatting"...

    The reason the script works in the console is because each statement is treated as a separate pipeline and their output, if any, are separated.
    If you execute the scipt as a oneliner in the console you will see the same bug.
    Format-Table prepends the blank line, you can omit it, and all other blank lines, by piping Format-Table's output to Out-String and use its -Stream switch, then filter out the empty strings:

    ... | ft ... -a | out-string -s | ? {$_}

    --
    Kiron

      My System SpecsSystem Spec

..."format-table command conflicting with the default formatting"... problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Format CDRW Failure: "Windows was unable to complete the format" Escher Vista General 5 29 Dec 2008
New Problem - "From" Address format in "Microsoft Communities" John Saunders [MVP] Live Mail 5 03 Apr 2008
"Open command prompt here" and "Copy as path" Moody Marco Vista performance & maintenance 10 04 May 2007
"Format-Table -autosize" as default Shafik PowerShell 4 21 Jan 2007
"format-table" command which is conflicting with the default formatting Norbert Kraft PowerShell 0 04 Jan 2007