How do I output text without a newline in PowerShell?

前端 未结 17 2289
独厮守ぢ
独厮守ぢ 2020-12-07 15:13

I want my PowerShell script to print something like this:

Enabling feature XYZ......Done

The script looks something like this:



        
17条回答
  •  抹茶落季
    2020-12-07 16:02

    I cheated, but I believe this is the only answer that addresses every requirement. Namely, this avoids the trailing CRLF, provides a place for the other operation to complete in the meantime, and properly redirects to stdout as necessary.

    $c_sharp_source = @"
    using System;
    namespace StackOverflow
    {
       public class ConsoleOut
       {
          public static void Main(string[] args)
          {
             Console.Write(args[0]);
          }
       }
    }
    "@
    $compiler_parameters = New-Object System.CodeDom.Compiler.CompilerParameters
    $compiler_parameters.GenerateExecutable = $true
    $compiler_parameters.OutputAssembly = "consoleout.exe"
    Add-Type -TypeDefinition $c_sharp_source -Language CSharp -CompilerParameters $compiler_parameters
    
    .\consoleout.exe "Enabling feature XYZ......."
    Write-Output 'Done.'
    

提交回复
热议问题