If Powershell command separator is ; (semicolon), why does “date; dir” make dir output extra details?












10














I understand that semicolon is a command separator in Powershell. echo "hello"; dir gives this output.



PS C:> echo "hello"; dir
hello

Directory: C:

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018-04-29 13:02 BCD_Backup
d----- 2018-12-02 14:08 Dell
<snip>


But why does date; dir give this output?



PS C:> date; dir

Friday, December 14, 2018 11:14:23

PSPath : Microsoft.PowerShell.CoreFileSystem::C:BCD_Backup
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
PSChildName : BCD_Backup
PSDrive : C
PSProvider : Microsoft.PowerShell.CoreFileSystem
PSIsContainer : True
Name : BCD_Backup
FullName : C:BCD_Backup
Parent :
Exists : True
Root : C:
Extension :
CreationTime : 2018-04-29 13:02:31
CreationTimeUtc : 2018-04-29 11:02:31
LastAccessTime : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime : 2018-04-29 13:02:31
LastWriteTimeUtc : 2018-04-29 11:02:31
Attributes : Directory
Mode : d-----
BaseName : BCD_Backup
Target : {}
LinkType :


PSPath : Microsoft.PowerShell.CoreFileSystem::C:Dell
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
<snip>









share|improve this question






















  • Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
    – LPChip
    Dec 14 at 10:33






  • 1




    also: vistax64.com/threads/powershell-and-the-semicolon.244649
    – LPChip
    Dec 14 at 10:38






  • 1




    I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
    – LotPings
    Dec 14 at 11:55










  • @LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
    – Michael Teter
    Dec 14 at 13:23










  • Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
    – LotPings
    Dec 14 at 13:30
















10














I understand that semicolon is a command separator in Powershell. echo "hello"; dir gives this output.



PS C:> echo "hello"; dir
hello

Directory: C:

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018-04-29 13:02 BCD_Backup
d----- 2018-12-02 14:08 Dell
<snip>


But why does date; dir give this output?



PS C:> date; dir

Friday, December 14, 2018 11:14:23

PSPath : Microsoft.PowerShell.CoreFileSystem::C:BCD_Backup
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
PSChildName : BCD_Backup
PSDrive : C
PSProvider : Microsoft.PowerShell.CoreFileSystem
PSIsContainer : True
Name : BCD_Backup
FullName : C:BCD_Backup
Parent :
Exists : True
Root : C:
Extension :
CreationTime : 2018-04-29 13:02:31
CreationTimeUtc : 2018-04-29 11:02:31
LastAccessTime : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime : 2018-04-29 13:02:31
LastWriteTimeUtc : 2018-04-29 11:02:31
Attributes : Directory
Mode : d-----
BaseName : BCD_Backup
Target : {}
LinkType :


PSPath : Microsoft.PowerShell.CoreFileSystem::C:Dell
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
<snip>









share|improve this question






















  • Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
    – LPChip
    Dec 14 at 10:33






  • 1




    also: vistax64.com/threads/powershell-and-the-semicolon.244649
    – LPChip
    Dec 14 at 10:38






  • 1




    I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
    – LotPings
    Dec 14 at 11:55










  • @LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
    – Michael Teter
    Dec 14 at 13:23










  • Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
    – LotPings
    Dec 14 at 13:30














10












10








10


3





I understand that semicolon is a command separator in Powershell. echo "hello"; dir gives this output.



PS C:> echo "hello"; dir
hello

Directory: C:

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018-04-29 13:02 BCD_Backup
d----- 2018-12-02 14:08 Dell
<snip>


But why does date; dir give this output?



PS C:> date; dir

Friday, December 14, 2018 11:14:23

PSPath : Microsoft.PowerShell.CoreFileSystem::C:BCD_Backup
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
PSChildName : BCD_Backup
PSDrive : C
PSProvider : Microsoft.PowerShell.CoreFileSystem
PSIsContainer : True
Name : BCD_Backup
FullName : C:BCD_Backup
Parent :
Exists : True
Root : C:
Extension :
CreationTime : 2018-04-29 13:02:31
CreationTimeUtc : 2018-04-29 11:02:31
LastAccessTime : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime : 2018-04-29 13:02:31
LastWriteTimeUtc : 2018-04-29 11:02:31
Attributes : Directory
Mode : d-----
BaseName : BCD_Backup
Target : {}
LinkType :


PSPath : Microsoft.PowerShell.CoreFileSystem::C:Dell
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
<snip>









share|improve this question













I understand that semicolon is a command separator in Powershell. echo "hello"; dir gives this output.



PS C:> echo "hello"; dir
hello

Directory: C:

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018-04-29 13:02 BCD_Backup
d----- 2018-12-02 14:08 Dell
<snip>


But why does date; dir give this output?



PS C:> date; dir

Friday, December 14, 2018 11:14:23

PSPath : Microsoft.PowerShell.CoreFileSystem::C:BCD_Backup
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
PSChildName : BCD_Backup
PSDrive : C
PSProvider : Microsoft.PowerShell.CoreFileSystem
PSIsContainer : True
Name : BCD_Backup
FullName : C:BCD_Backup
Parent :
Exists : True
Root : C:
Extension :
CreationTime : 2018-04-29 13:02:31
CreationTimeUtc : 2018-04-29 11:02:31
LastAccessTime : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime : 2018-04-29 13:02:31
LastWriteTimeUtc : 2018-04-29 11:02:31
Attributes : Directory
Mode : d-----
BaseName : BCD_Backup
Target : {}
LinkType :


PSPath : Microsoft.PowerShell.CoreFileSystem::C:Dell
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:
<snip>






command-line powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 14 at 10:18









Michael Teter

512




512












  • Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
    – LPChip
    Dec 14 at 10:33






  • 1




    also: vistax64.com/threads/powershell-and-the-semicolon.244649
    – LPChip
    Dec 14 at 10:38






  • 1




    I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
    – LotPings
    Dec 14 at 11:55










  • @LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
    – Michael Teter
    Dec 14 at 13:23










  • Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
    – LotPings
    Dec 14 at 13:30


















  • Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
    – LPChip
    Dec 14 at 10:33






  • 1




    also: vistax64.com/threads/powershell-and-the-semicolon.244649
    – LPChip
    Dec 14 at 10:38






  • 1




    I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
    – LotPings
    Dec 14 at 11:55










  • @LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
    – Michael Teter
    Dec 14 at 13:23










  • Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
    – LotPings
    Dec 14 at 13:30
















Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
– LPChip
Dec 14 at 10:33




Interesting question. I hope it gets answered, because I have no idea myself, and I know my way around powershell.
– LPChip
Dec 14 at 10:33




1




1




also: vistax64.com/threads/powershell-and-the-semicolon.244649
– LPChip
Dec 14 at 10:38




also: vistax64.com/threads/powershell-and-the-semicolon.244649
– LPChip
Dec 14 at 10:38




1




1




I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
– LotPings
Dec 14 at 11:55




I think this BUG is the result of PowerShells feature to postpone/defer output to not insert the same header for successive commands and seems to exist for quite a long time.
– LotPings
Dec 14 at 11:55












@LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
– Michael Teter
Dec 14 at 13:23




@LotPings - what's fascinating is that Get-ChildItem doesn't appear to have any options that would generate the output that > date; Get-ChildItem results in.
– Michael Teter
Dec 14 at 13:23












Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
– LotPings
Dec 14 at 13:30




Agreed, I'm also curious what is executed with date at all. It's not an alias nor a cmdlet or .exe file (same issue in PSv6 BTW)
– LotPings
Dec 14 at 13:30










2 Answers
2






active

oldest

votes


















2














As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.



As Get-Date returns an object of DateTime type, it gets formatted as list, affecting your 'dir' output.



You can test this assumption by changing return type of Get-Date to string using 'format' option:



date -Format yyyy-MM-dd ; dir


(this will produce default output for 'dir')



Or by changing default output formatting by pipelining it to Format-Table:



 date | Format-Table ; dir





share|improve this answer





























    0














    This seems to only occur when you use date; 'almost anything else after' that including other PS cmdlets (just tried a few).



    'date' as typed appears to be calling core Windows (just like cmd.exe) to get that datestring back, PowerShell is trying to do something with that string it appears.



    If you reverse this, 'anything here';date, does not exhibit this oddity. It just does this...



     dir;date


    Directory: D:Scripts


    Mode LastWriteTime Length Name
    ---- ------------- ------ ----
    d----- 9/1/2018 2:12 PM .vscode
    d----- 7/3/2018 4:44 PM CheckURI

    ....


    DisplayHint : DateTime
    Date : 12/14/2018 12:00:00 AM
    Day : 14
    DayOfWeek : Friday
    DayOfYear : 348
    Hour : 14
    Kind : Local
    Millisecond : 516
    Minute : 42
    Month : 12
    Second : 22
    Ticks : 636803953425164049
    TimeOfDay : 14:42:22.5164049
    Year : 2018
    DateTime : Friday, December 14, 2018 2:42:22 PM





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1383533%2fif-powershell-command-separator-is-semicolon-why-does-date-dir-make-dir%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.



      As Get-Date returns an object of DateTime type, it gets formatted as list, affecting your 'dir' output.



      You can test this assumption by changing return type of Get-Date to string using 'format' option:



      date -Format yyyy-MM-dd ; dir


      (this will produce default output for 'dir')



      Or by changing default output formatting by pipelining it to Format-Table:



       date | Format-Table ; dir





      share|improve this answer


























        2














        As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.



        As Get-Date returns an object of DateTime type, it gets formatted as list, affecting your 'dir' output.



        You can test this assumption by changing return type of Get-Date to string using 'format' option:



        date -Format yyyy-MM-dd ; dir


        (this will produce default output for 'dir')



        Or by changing default output formatting by pipelining it to Format-Table:



         date | Format-Table ; dir





        share|improve this answer
























          2












          2








          2






          As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.



          As Get-Date returns an object of DateTime type, it gets formatted as list, affecting your 'dir' output.



          You can test this assumption by changing return type of Get-Date to string using 'format' option:



          date -Format yyyy-MM-dd ; dir


          (this will produce default output for 'dir')



          Or by changing default output formatting by pipelining it to Format-Table:



           date | Format-Table ; dir





          share|improve this answer












          As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.



          As Get-Date returns an object of DateTime type, it gets formatted as list, affecting your 'dir' output.



          You can test this assumption by changing return type of Get-Date to string using 'format' option:



          date -Format yyyy-MM-dd ; dir


          (this will produce default output for 'dir')



          Or by changing default output formatting by pipelining it to Format-Table:



           date | Format-Table ; dir






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 18 at 12:02









          mikalai

          1213




          1213

























              0














              This seems to only occur when you use date; 'almost anything else after' that including other PS cmdlets (just tried a few).



              'date' as typed appears to be calling core Windows (just like cmd.exe) to get that datestring back, PowerShell is trying to do something with that string it appears.



              If you reverse this, 'anything here';date, does not exhibit this oddity. It just does this...



               dir;date


              Directory: D:Scripts


              Mode LastWriteTime Length Name
              ---- ------------- ------ ----
              d----- 9/1/2018 2:12 PM .vscode
              d----- 7/3/2018 4:44 PM CheckURI

              ....


              DisplayHint : DateTime
              Date : 12/14/2018 12:00:00 AM
              Day : 14
              DayOfWeek : Friday
              DayOfYear : 348
              Hour : 14
              Kind : Local
              Millisecond : 516
              Minute : 42
              Month : 12
              Second : 22
              Ticks : 636803953425164049
              TimeOfDay : 14:42:22.5164049
              Year : 2018
              DateTime : Friday, December 14, 2018 2:42:22 PM





              share|improve this answer




























                0














                This seems to only occur when you use date; 'almost anything else after' that including other PS cmdlets (just tried a few).



                'date' as typed appears to be calling core Windows (just like cmd.exe) to get that datestring back, PowerShell is trying to do something with that string it appears.



                If you reverse this, 'anything here';date, does not exhibit this oddity. It just does this...



                 dir;date


                Directory: D:Scripts


                Mode LastWriteTime Length Name
                ---- ------------- ------ ----
                d----- 9/1/2018 2:12 PM .vscode
                d----- 7/3/2018 4:44 PM CheckURI

                ....


                DisplayHint : DateTime
                Date : 12/14/2018 12:00:00 AM
                Day : 14
                DayOfWeek : Friday
                DayOfYear : 348
                Hour : 14
                Kind : Local
                Millisecond : 516
                Minute : 42
                Month : 12
                Second : 22
                Ticks : 636803953425164049
                TimeOfDay : 14:42:22.5164049
                Year : 2018
                DateTime : Friday, December 14, 2018 2:42:22 PM





                share|improve this answer


























                  0












                  0








                  0






                  This seems to only occur when you use date; 'almost anything else after' that including other PS cmdlets (just tried a few).



                  'date' as typed appears to be calling core Windows (just like cmd.exe) to get that datestring back, PowerShell is trying to do something with that string it appears.



                  If you reverse this, 'anything here';date, does not exhibit this oddity. It just does this...



                   dir;date


                  Directory: D:Scripts


                  Mode LastWriteTime Length Name
                  ---- ------------- ------ ----
                  d----- 9/1/2018 2:12 PM .vscode
                  d----- 7/3/2018 4:44 PM CheckURI

                  ....


                  DisplayHint : DateTime
                  Date : 12/14/2018 12:00:00 AM
                  Day : 14
                  DayOfWeek : Friday
                  DayOfYear : 348
                  Hour : 14
                  Kind : Local
                  Millisecond : 516
                  Minute : 42
                  Month : 12
                  Second : 22
                  Ticks : 636803953425164049
                  TimeOfDay : 14:42:22.5164049
                  Year : 2018
                  DateTime : Friday, December 14, 2018 2:42:22 PM





                  share|improve this answer














                  This seems to only occur when you use date; 'almost anything else after' that including other PS cmdlets (just tried a few).



                  'date' as typed appears to be calling core Windows (just like cmd.exe) to get that datestring back, PowerShell is trying to do something with that string it appears.



                  If you reverse this, 'anything here';date, does not exhibit this oddity. It just does this...



                   dir;date


                  Directory: D:Scripts


                  Mode LastWriteTime Length Name
                  ---- ------------- ------ ----
                  d----- 9/1/2018 2:12 PM .vscode
                  d----- 7/3/2018 4:44 PM CheckURI

                  ....


                  DisplayHint : DateTime
                  Date : 12/14/2018 12:00:00 AM
                  Day : 14
                  DayOfWeek : Friday
                  DayOfYear : 348
                  Hour : 14
                  Kind : Local
                  Millisecond : 516
                  Minute : 42
                  Month : 12
                  Second : 22
                  Ticks : 636803953425164049
                  TimeOfDay : 14:42:22.5164049
                  Year : 2018
                  DateTime : Friday, December 14, 2018 2:42:22 PM






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 16 at 22:57

























                  answered Dec 14 at 22:46









                  postanote

                  92223




                  92223






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1383533%2fif-powershell-command-separator-is-semicolon-why-does-date-dir-make-dir%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                      Eduardo VII do Reino Unido