Multiline variable into a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Nico
Posts: 2
Joined: 25 Feb 2014 04:25

Multiline variable into a file

#1 Post by Nico » 25 Feb 2014 04:38

Hello.
I have something that puts in a variable a changelog.
It looks like that :
# Amélioration
- [STR-275] Empecher de dumper les bases/tables vers le serveur source
# Bogue
- [STR-143] Impossible d'imprimer ou éditer le détail des contenants en Pilote
- [STR-277] Indication de la Cale d'une Ké7 dans l'écran Ajustement
- [STR-280] Le co_tranche vide n'est jamais détecté et provoque un plnateg de requete INSERT INTO DEPOTS_FACT
- [STR-282] S24 F7 GENERATION AUTOMATIQUE DES NOMS DE PRODUITS INCORRECT POUR MD7 PROST SECTORIELLE
- [STR-55] Il manque des données à l'affichage de 'Gérer les lots' / modifs params
- [STR-283] IMPOSSIBLE DE CREER UN EXPEDITEUR
- [STR-274] Impossible de créer un DDG WT lorsque le dépôt comporte trop de batchs
- [STR-264] Afficher bordereau - colonne batch non valorisée


It does it progammaticaly, and I want to write this into a file. The problem with

Code: Select all

echo %variable%>file.txt

is that it sends me this "echo ("# Am‚lioration" and never save it in file.txt.
I googled for a day now without success, and I stumble upon this forum where it seems possible to find an answer.
I can't manually interact with the variable as it is automatically generated.

Please help me !
Thanks in advance.

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Multiline variable into a file

#2 Post by jeb » 25 Feb 2014 05:53

Hi Nico,

simple by using delayed expansion.

Code: Select all

setlocal EnableDelayedExpansion
echo !variable! >file


The cause for your is, that a linefeed stops the parser in an early phase.
But with delayed expansion the expansion is done after this phase.

How does the Windows Command Interpreter (CMD.EXE) parse scripts?

jeb

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Multiline variable into a file

#3 Post by Squashman » 25 Feb 2014 07:34

Just want to make sure you know that the > symbol will overwrite the file whereas >> will append to the file.

Nico
Posts: 2
Joined: 25 Feb 2014 04:25

Re: Multiline variable into a file

#4 Post by Nico » 26 Feb 2014 04:24

Well, it doesn't work but I found why.
It appears that the software I use to generate %variable% replace directly the %variable% in the command batch instead of assigning the value to %variable% and then using it.
It can't work...
Thanks anyway!

Post Reply