1

Is there any way to achieve this without the need of external resources as Bash does?

I'd like to prompt user for input and copy the input into a variable in case it is multilined as well (for instance if he or she copy-pastes a text onto the prompt)

Perhaps using Powershell -command?

Whimusical
  • 6,401
  • 11
  • 62
  • 105
  • This is not a duplicate of the aforementioned, as solutions seem focused on the particular needs of the poster (outputing to a file) whereas mine is inputting from prompt – Whimusical May 13 '14 at 13:13
  • In a Batch `set /P` command, if the user enters a multiline input just the first line is read. There is no way to detect if one keyboard input is comprised of several lines, and I think the same point is true no matter the shell/application/language involved. BTW note that your question is _not_ related to a "heredoc" document... – Aacini May 13 '14 at 17:29

1 Answers1

1

As Aacini mentioned, it's not possible to use a single set /p.
You could use a loop of set /p, but you need a type of end marker to leave the loop.

Or you could use copy con input.tmp, but then you have to finish the input with CTRL-Z.

A sample with sep /p stopping at the first empty line.

@echo off
setlocal EnableDelayedExpansion
SET LF=^


REM ** Two empty lines are required
call :input
echo !input!
exit /b


:input
set "input="
:inputLoop
set "line="
set /p "line=Enter text, stop with an empty line :"
if defined line (
    set "input=!input!!line!!LF!"
    goto :inputLoop
)
exit /b
jeb
  • 78,592
  • 17
  • 171
  • 225