0

i want to make a start.config file by using bat script. I want to add to my config file that parameter:

StartAgents=9

WITHOUT space at the end of line.

Unfortunately command:

echo StartAgents=9>>C:\start.config

not working, I think that there is "collision" with two characters: "9>"

Command:

echo StartAgents=9 >>C:\start.config

is working, but this is adding space at the end of line in my config file - i dont want that.

Any ideas how to do that?

I want to add line StartAgents=9 without space af the end of line. want:

StartAgents=9

dont want:

StartAgents=9 
Boniek
  • 13
  • 4
  • `1>>C:\start.config (echo StartAgents=9)` – T3RR0R Dec 29 '22 at 15:46
  • 3
    You are trying to echo Stream9 (which is empty) to the file. Use `>file echo 9` or `(echo 9) > file` (where `>` is just an abbreviation of the correct form `1>` / `[StreamID]>`) – Stephan Dec 29 '22 at 15:46
  • 1
    @Stephan Yes! I totally forgot about that one - obligatory [oldnewthing](https://devblogs.microsoft.com/oldnewthing/20170731-00/?p=96715). – Christian.K Dec 29 '22 at 15:57

1 Answers1

2

You have to escape the number, so that it isn't interpreted by CMD.EXE as a file descriptor number.

Then you can add the >> redirection directly after the number to not insert a trailing space.

Example:

echo StartAgent=^9>>test.txt

Related Information:

Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • 1
    Make sure you also consider @Stephan's comment. The notation to put the redirection _before_ the `echo` is actually quite useful too (I totally forgot that one ;-)) – Christian.K Dec 29 '22 at 15:56