Echo multi-line string does not work, but typing multi-line file works.
Why, how could i achieve it with echo?

Code: Select all
setlocal enableDelayedExpansion
(set \n=^
%=DONT REMOVE THIS=%
)
for /f %%G in ("abc!\n!xyz!\n!") do echo Line: %%G
echo ----
rem Passing multiple lines from batch "echo" to openssl does not work
echo abc!\n!xyz!\n! | openssl base64
rem decode (-d) passed string
echo abc!\n!xyz!\n! | openssl base64 | openssl base64 -d
rem Passing multiple lines from batch "echo" to powershell script does not work
echo abc!\n!exit!\n! | Powershell.exe -Noprofile -File test.ps1
rem Passing multiple lines from batch "echo" to powershell does not work
echo abc!\n!exit!\n! | Powershell.exe -Noprofile "openssl base64 | openssl base64 -d"
rem Passing multiple lines from batch "type" to powershell works
echo abc!\n!xyz!\n! > lines.txt
type lines.txt
type lines.txt | Powershell.exe -Noprofile "openssl base64"
type lines.txt | Powershell.exe -Noprofile "openssl base64 | openssl base64 -d"
Powershell.exe -Noprofile "echo abc`nexit`n" | Powershell.exe -Noprofile "openssl base64 | openssl base64 -d"
Powershell.exe -Noprofile "echo abc`rexit`r" | Powershell.exe -Noprofile "openssl base64 | openssl base64 -d"
Code: Select all
# test.ps1
# $s=[Console]::In.ReadLine();
# Read further characters
while (($c=[Console]::In.Read()) -ne -1) {
write-host ([char]$c) -nonewline
}
Code: Select all
# Alternative test.ps1
param(
[parameter(ValueFromPipeline)]$string
)
echo "string value $string"
# Edit: added if statement
if($string){
$in = "$string"
}else{
$in = read-host -prompt "input"
}
Write-Host Result $in