Page 1 of 1
Set a multiline variable
Posted: 05 Feb 2021 18:26
by avizee
.
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
Re: Set a multiline variable
Posted: 05 Feb 2021 19:25
by ShadowThief
What are the exact contents that you expect %COMPUTERNAME%.xml to have?
Re: Set a multiline variable
Posted: 05 Feb 2021 23:59
by avizee
echo.[+] %check_code% -> Not working!!!
Re: Set a multiline variable
Posted: 06 Feb 2021 00:13
by ShadowThief
Well then you're going to have to change your code. If you had wanted the contents of the file to be
Code: Select all
> nul& echo.[+] %check_code% & echo.============================================================================= >> %COMPUTERNAME%.xml 2> nul
then you could have just done
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
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.
Re: Set a multiline variable
Posted: 06 Feb 2021 03:21
by T3RRY
avizee wrote: ↑05 Feb 2021 23:59
echo.[+] %check_code% -> Not working!!!
As shadowthief has already asked, What output do you actually expect?
If you require this output:
Code: Select all
[+] Part_001
=============================================================================
You can use a macro like this:
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%
If this is not the output your aiming for, provide a clear example of the expected output.
Set a multiline variable (echo now working)
Posted: 06 Feb 2021 08:59
by avizee
I did not write the previous question specifically, so I rewrite it.
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
- code_.png (17.48 KiB) Viewed 8148 times
And I want this
- code_result.png (4.79 KiB) Viewed 8148 times
But result is like this
- code_result_screenshot.png (5.13 KiB) Viewed 8148 times
Trying to use variables instead of functions
Plz help!!!
Re: Set a multiline variable
Posted: 06 Feb 2021 09:16
by avizee
T3RRY wrote: ↑06 Feb 2021 03:21
avizee wrote: ↑05 Feb 2021 23:59
echo.[+] %check_code% -> Not working!!!
As shadowthief has already asked, What output do you actually expect?
If you require this output:
Code: Select all
[+] Part_001
=============================================================================
You can use a macro like this:
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%
If this is not the output your aiming for, provide a clear example of the expected output.
Thanks for the comment
I wrote again
viewtopic.php?f=3&t=9951
Re: Set a multiline variable (echo now working)
Posted: 06 Feb 2021 10:48
by ShadowThief
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
Code: Select all
echo >nul & echo.[+] %check_code% & echo.===========================================================================-= >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul
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?
Re: Set a multiline variable (echo now working)
Posted: 06 Feb 2021 20:05
by avizee
ShadowThief wrote: ↑06 Feb 2021 10:48
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
Code: Select all
echo >nul & echo.[+] %check_code% & echo.===========================================================================-= >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul >> [F_RESULT]__%COMPUTERNAME%.xml 2> nul
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?
I wrote a new post because I am not used to using the forum.
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
Posted: 06 Feb 2021 23:36
by Squashman
Both threads have been merged
Re: Set a multiline variable
Posted: 06 Feb 2021 23:53
by avizee
Squashman wrote: ↑06 Feb 2021 23:36
Both threads have been merged
Thanks!
Re: Set a multiline variable
Posted: 06 Feb 2021 23:54
by avizee
T3RRY wrote: ↑06 Feb 2021 03:21
avizee wrote: ↑05 Feb 2021 23:59
echo.[+] %check_code% -> Not working!!!
As shadowthief has already asked, What output do you actually expect?
If you require this output:
Code: Select all
[+] Part_001
=============================================================================
You can use a macro like this:
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%
If this is not the output your aiming for, provide a clear example of the expected output.
Wow!
It's a brilliant idea
Re: Set a multiline variable (echo now working)
Posted: 07 Feb 2021 03:39
by T3RRY
avizee wrote: ↑06 Feb 2021 20:05
I want to be displayed on the screen '
[+] SRV-001'
To be put into a text file '
===========================================================================-='
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)
Posted: 09 Feb 2021 08:08
by avizee
T3RRY wrote: ↑07 Feb 2021 03:39
avizee wrote: ↑06 Feb 2021 20:05
I want to be displayed on the screen '
[+] SRV-001'
To be put into a text file '
===========================================================================-='
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%
Thanks for the help
Thanks to you, I clock out early