What does a forward slash before a pipe in cmd do

2019-07-22 12:28发布

This code:

    @echo off
    echo/|set /p ="Executing backup...."
    echo/|set /p =" backup procedure"

... came from Echoing in the same line and produces the below output in a cmd window:

    Executing backup....backup procedure

However, I cant seem to find an explanation through google on what the forward slash does to the ¿pipe? to cause set's output to be echoed to the console / stdout

If anyone could also suggest a good website for learning more about cmd / cmd programs' features like this, it would be appreciated.

2条回答
家丑人穷心不美
2楼-- · 2019-07-22 12:57

Care of https://stackoverflow.com/users/1201210/tenterhook

1) echo prints the result of set /p =... with or without the / before the pipe, so I'm not sure what your question is asking

2) (It will also print set /p =... with random junk after the echo, too, since it's reading the piped stuff and not the arguments it receives.)

I will hence suggest edits to the referenced SO post, to prevent others confusion.

查看更多
萌系小妹纸
3楼-- · 2019-07-22 13:12

The echo/ is simply a way of printing only an empty line, instead of ECHO IS ON for a single echo.

But in this case it's completly unimportant, as the only use of the echo is for creating some stuff for the pipe, so the set /p will not wait for user input.

But this way to echo text without a linefeed is very inefficient, as a pipe creates two new instances of cmd.exe.
It's much simpler and faster to use

<nul set /p "=My Text"

The redirect from NUL will also stop the waiting for user input.

查看更多
登录 后发表回答