Redirecting command input using <

前端 未结 2 336
情话喂你
情话喂你 2021-01-15 19:11

Input redirection is working for .exe files or internal windows commands.

    app.exe < ListOfNames.txt
    sort < input.txt

However

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 20:00

    Parameters that are provided on the command line are completely different than stdin ( where your redirected input goes). This is true for both batch scripts as well as .exe programs.

    Some programs are designed to accept the same values via command line arguments or stdin. But that is not the norm. That is a feature that is provided by the developer of the program.

    If you want to read redirected input within a batch script, then you must do one of the following.

    To read a single line:

    set /p "ln="
    echo %ln%
    

    To read all lines in a loop:

    for /f "delims=" %%A in ('findstr "^"') do (
      echo %%A
    )
    

提交回复
热议问题