How to output something in PowerShell

前端 未结 7 981
北恋
北恋 2020-12-04 07:43

I am running a PowerShell script from within a batch file. The script fetches a web page and checks whether the page\'s content is the string \"OK\".

The PowerShell

7条回答
  •  悲哀的现实
    2020-12-04 08:40

    You simply cannot get PowerShell to ommit those pesky newlines. There is no script or cmdlet that does this.

    Of course Write-Host is absolute nonsense because you can't redirect/pipe from it! You simply have to write your own:

    using System;
    
    namespace WriteToStdout
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args != null)
                {
                    Console.Write(string.Join(" ", args));
                }
            }
        }
    }
    

    E.g.

    PS C:\> writetostdout finally I can write to stdout like echo -n
    finally I can write to stdout like echo -nPS C:\>
    

提交回复
热议问题