Windows batch: echo without new line

后端 未结 18 1442
失恋的感觉
失恋的感觉 2020-11-22 04:01

What is the Windows batch equivalent of the Linux shell command echo -n which suppresses the newline at the end of the output?

The idea is to write on t

18条回答
  •  旧时难觅i
    2020-11-22 04:40

    Here is another method, it uses Powershell Write-Host which has a -NoNewLine parameter, combine that with start /b and it offers the same functionality from batch.

    NoNewLines.cmd

    @ECHO OFF
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 1 - ';Write-Host -NoNewLine 'Result 2 - ';Write-Host -NoNewLine 'Result 3 - '"
    PAUSE
    

    Output

    Result 1 - Result 2 - Result 3 - Press any key to continue . . .
    

    This one below is slightly different, doesn't work exactly like the OP wants, but is interesting because each result overwrites the previous result emulating a counter.

    @ECHO OFF
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 1 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 2 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 3 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 4 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 5 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 6 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 7 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 8 - '"
    start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 9 - '"
    PAUSE
    

提交回复
热议问题