Set a multiline variable
Moderator: DosItHelp
Set a multiline variable
.
Thanks for the comment
I wrote again
viewtopic.php?f=3&t=9951
===================================================================================
I'm trying to echo a variable made of multiple lines
But "echo.[+] %check_code%" doesn't work
How can it be possible
Thank you for your help
------------------------------------------------------------------------
@echo off
SETLOCAL
set "header=> nul& echo.[+] %check_code% & echo.===========================================================================-= >> %COMPUTERNAME%.xml 2> nul"
set "check_code=Part_001"
echo %header% >>%COMPUTERNAME%.xml 2> nul
Thanks for the comment
I wrote again
viewtopic.php?f=3&t=9951
===================================================================================
I'm trying to echo a variable made of multiple lines
But "echo.[+] %check_code%" doesn't work
How can it be possible
Thank you for your help
------------------------------------------------------------------------
@echo off
SETLOCAL
set "header=> nul& echo.[+] %check_code% & echo.===========================================================================-= >> %COMPUTERNAME%.xml 2> nul"
set "check_code=Part_001"
echo %header% >>%COMPUTERNAME%.xml 2> nul
Last edited by avizee on 06 Feb 2021 09:19, edited 1 time in total.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Set a multiline variable
What are the exact contents that you expect %COMPUTERNAME%.xml to have?
Re: Set a multiline variable
echo.[+] %check_code% -> Not working!!!
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Set a multiline variable
Well then you're going to have to change your code. If you had wanted the contents of the file to be
then you could have just done
Unfortunately, you've stated that the line of ==s isn't supposed to be part of the output file, which means that you'll need to delete the & and everything after it from the line where you set the %header% variable.
Code: Select all
> nul& echo.[+] %check_code% & echo.============================================================================= >> %COMPUTERNAME%.xml 2> nul
Code: Select all
@echo off
SETLOCAL enabledelayedexpansion
set "header=> nul& echo.[+] %%check_code%% & echo.============================================================================= >> %%COMPUTERNAME%%.xml 2> nul"
set "check_code=Part_001"
echo !header! >>%COMPUTERNAME%.xml 2> nul
Re: Set a multiline variable
As shadowthief has already asked, What output do you actually expect?
If you require this output:
Code: Select all
[+] Part_001
=============================================================================
Code: Select all
@Echo off
(Set LF=^
%= Linefeed variable. Don not modify this or above 2 lines. =%)
@echo off
SETLOCAL enabledelayedexpansion
set "header=>> "%~dp0%COMPUTERNAME%.xml" Echo([+] ?^^^!LF^^^!============================================================================="
%Header:?=Part_001%
Set a multiline variable (echo now working)
I did not write the previous question specifically, so I rewrite it.
This is my batch code
And I want this
But result is like this
Trying to use variables instead of functions
Plz help!!!
This is my batch code
Code: Select all
@echo off
SETLOCAL
set "header=> nul& echo.[+] %check_code% & echo.===========================================================================-= >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul"
set "check_code=SRV-001"
echo %header% >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul
And I want this
But result is like this
Trying to use variables instead of functions
Plz help!!!
Re: Set a multiline variable
T3RRY wrote: ↑06 Feb 2021 03:21As shadowthief has already asked, What output do you actually expect?
If you require this output:You can use a macro like this:Code: Select all
[+] Part_001 =============================================================================
If this is not the output your aiming for, provide a clear example of the expected output.Code: Select all
@Echo off (Set LF=^ %= Linefeed variable. Don not modify this or above 2 lines. =%) @echo off SETLOCAL enabledelayedexpansion set "header=>> "%~dp0%COMPUTERNAME%.xml" Echo([+] ?^^^!LF^^^!=============================================================================" %Header:?=Part_001%
Thanks for the comment
I wrote again
viewtopic.php?f=3&t=9951
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Set a multiline variable (echo now working)
You could have stayed in the original thread.
You have to set variables BEFORE you use them, so move the set check_code line above the set header line. Also, that first >> [F_RESULT]__%COMPUTERNAME%.xml 2>nul being inside of the set header line means that your last line is saying
You still haven't shown an example of what you're looking for, which tells me that you want [+] SRV-001 to be displayed on the screen and for ===========================================================================-= to be put into a text file, but you don't want [+] SRV-001 to be put into that same text file. Is that correct?
You have to set variables BEFORE you use them, so move the set check_code line above the set header line. Also, that first >> [F_RESULT]__%COMPUTERNAME%.xml 2>nul being inside of the set header line means that your last line is saying
Code: Select all
echo >nul & echo.[+] %check_code% & echo.===========================================================================-= >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul
Re: Set a multiline variable (echo now working)
I wrote a new post because I am not used to using the forum.ShadowThief wrote: ↑06 Feb 2021 10:48You could have stayed in the original thread.
You have to set variables BEFORE you use them, so move the set check_code line above the set header line. Also, that first >> [F_RESULT]__%COMPUTERNAME%.xml 2>nul being inside of the set header line means that your last line is sayingYou still haven't shown an example of what you're looking for, which tells me that you want [+] SRV-001 to be displayed on the screen and for ===========================================================================-= to be put into a text file, but you don't want [+] SRV-001 to be put into that same text file. Is that correct?Code: Select all
echo >nul & echo.[+] %check_code% & echo.===========================================================================-= >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul
I'm sorry about that
I want to tell you exactly what I want
It's correct.
I want to be displayed on the screen '[+] SRV-001'
To be put into a text file '===========================================================================-='
Re: Set a multiline variable
Both threads have been merged
Re: Set a multiline variable
Wow!T3RRY wrote: ↑06 Feb 2021 03:21As shadowthief has already asked, What output do you actually expect?
If you require this output:You can use a macro like this:Code: Select all
[+] Part_001 =============================================================================
If this is not the output your aiming for, provide a clear example of the expected output.Code: Select all
@Echo off (Set LF=^ %= Linefeed variable. Don not modify this or above 2 lines. =%) @echo off SETLOCAL enabledelayedexpansion set "header=>> "%~dp0%COMPUTERNAME%.xml" Echo([+] ?^^^!LF^^^!=============================================================================" %Header:?=Part_001%
It's a brilliant idea
Re: Set a multiline variable (echo now working)
That output is simpler still, and does not require a multiline variable. It's just Concatenated commands that sends one string of output to stdout, and redirects the other to a file.
The approach I've demonstrated is a simple macro function that uses substring modification to replace '?' with the string to be output to stdout.
Code: Select all
@Echo off
set "header=>> "%~dp0%COMPUTERNAME%.xml" (Echo(===========================================================================-=)&Echo([+] ?"
%Header:?=SRV_001%
Re: Set a multiline variable (echo now working)
Thanks for the helpT3RRY wrote: ↑07 Feb 2021 03:39That output is simpler still, and does not require a multiline variable. It's just Concatenated commands that sends one string of output to stdout, and redirects the other to a file.
The approach I've demonstrated is a simple macro function that uses substring modification to replace '?' with the string to be output to stdout.
Code: Select all
@Echo off set "header=>> "%~dp0%COMPUTERNAME%.xml" (Echo(===========================================================================-=)&Echo([+] ?" %Header:?=SRV_001%
Thanks to you, I clock out early