0

I Googled it but i'm not able to find a GOOD solution.

My goal is to put a string which is composed of 6 lines in one string, and only one, in a variable.

For example, my string can look like :

a
b
c

and I want it to be in one string. I tried the thing witch ^, or with ECHO " " but it doesn't work : the cmd put an error "not recognized as an internal command" (and it's normal, it's just some sentences, not batch commands!)

Thanks, Clément

Clement B
  • 218
  • 1
  • 4
  • 14

2 Answers2

0

Not so simple but possible :

@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
setlocal enableDelayedExpansion
set "string_with_new_lines=a!nl!b!nl!c"
echo %string_with_new_lines%

Aacini has a simpler solution for this using empty variable,but I'm struggle to find the link.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • It looks like it works for "a b c" but i'm using it for SQL (exactly SPARQL) commands and it's not working. Indeed : `set "string_with_new_lines=PREFIX resources: !nl!" echo %string_with_new_lines%` doesn't work. Any ideas ? – Clement B Oct 05 '17 at 08:46
  • @ClementB - what is the error message? Are you using `<` and `>` in your code? If yes they should be escaped with caret: `^<` and `^>` . Better paste the whole code you want to execute ,because it will be easier to help you. – npocmaka Oct 05 '17 at 08:58
  • Hey. It doesn't counter the `<` symbol. In reality, it does but after that, the !nl! is ignored. – Clement B Oct 05 '17 at 12:02
  • @ClementB - please paste more code in your question. If you want to pass multiline parameter probably it wont be possible. Probably your tool can accept SQL script file as argument? – npocmaka Oct 05 '17 at 12:04
  • By the way, your idea of a file is genius. I'll try this immedialty. – Clement B Oct 05 '17 at 12:36
0

Following the comments on the post answer of @npocmaka

It's currently in Python, so the """ thing works.

requete = """
            PREFIX resources: <http://www.fluidops.com/resource/> 
            SELECT DISTINCT ?id ?marque ?modele WHERE { 
              ?voiture resources:uid ?id.
              ?voiture resources:bpqmqvc ?marque. #myComment
              ?voiture resources:bpqmodvc ?modele 
            } 
        """
Clement B
  • 218
  • 1
  • 4
  • 14