0

I tryed but I cannot find something similar. How can I redirect a file containing special characters to a variable with CMD inside a batch-file.

Text:

MSCF    T       ,               >    
         8Oíà  ~ /2Wõ
 CK¾M-.NLOUÓÕ

code:

setlocal EnableDelayedExpansion
set /p msg=<[file]
echo !msg!

output:

MSCF

Is being some redirection done because of the MSCF characters but not sure what's happening...

SNR
  • 712
  • 1
  • 8
  • 22
  • Do you expect multi line text in your variable? At least, you should use `echo !msg!`, as `echo msg` will always output the text `msg` – jeb Sep 24 '19 at 15:23
  • I can't reproduce your output, you should see the first line (full) – jeb Sep 24 '19 at 15:26
  • @jeb typo error. No, I can't see first line. However I can `type` the file and see the full text. – SNR Sep 24 '19 at 15:28
  • Still the question: Do you expect multiple lines in your variable? You could try it with [SO:Assign output of a program to a variable using a MS batch file](https://stackoverflow.com/a/54425285/463115). but if your content is more or less binary it won't work (Like NULL bytes) – jeb Sep 24 '19 at 15:30
  • What happens when you use the recommended doublequotes, `Set /P "msg="<"file"`? – Compo Sep 24 '19 at 15:34
  • @Compo same behaviour. How can I allow special characters into `cmd`? – SNR Sep 24 '19 at 15:38
  • As already stated, your code works exactly as expected using the exact content you have posted. That means that what you've posted, or at least what has been determined by the forum as your content is not an accurate representation of the actual file content. @jeb asked a question and has expanded upon it, yet you've seemingly decided not to answer it, so I'll expand still further `Set /P "msg="<"file"` will save the content of the first line of `"file"` it will not read any other line, so if you're looking for multiline output, you've chosen the wrong method. – Compo Sep 24 '19 at 16:11
  • 1
    I think, [this related question](https://stackoverflow.com/questions/58066181/can-i-take-a-lan-message-sent-to-me-and-put-it-into-a-program-to-decrypt-it) is useful to understand and recreate the file (the file actually has one line, but a lot of non-ANSI characters, not displayable on this site) – Stephan Sep 24 '19 at 16:19
  • @Stephan I wrote that answer and this question comes from it. – SNR Sep 24 '19 at 18:11
  • @jeb multi line is not an issue we can do a `for` loop to read each line. – SNR Sep 24 '19 at 18:29
  • @SNR I'm well aware of that. You could have spared us a lot of confusion and comments if you gave that info (or at least the method to get that string) in your question. By the way: how do you plan to get the message from the message box into a file or variable? – Stephan Sep 24 '19 at 19:42
  • @Stephan You are right, sorry. I am lost with the message box here, can you explain me? – SNR Sep 25 '19 at 08:29
  • @SNR: sorry, `cmd` has no method to communicate with GUI Elements. That's why I was curious how you would approach that problem. – Stephan Sep 25 '19 at 08:34
  • @Stephan But I think I don't need to since `msg` just send a message over a network. – SNR Sep 25 '19 at 08:40

0 Answers0