0

that it weird with the ">>" in batch file. i could run echo. >>test command line direct key in the cmd window and get the ouput in expected.

but if you write in the bat, for example: when i write a test.bat with code echo. >> test

there will run in cmd with code echo. 1>> test

i have no idea why it would be, and nobody discus with. it not have bug happen until now, but i afraid of it had happen without findding out.

my default chcp is 950, because i using some variable with chinese context, there is someone advice me to use chcp 65001, but the problem still happen

does someone have any advice?

Hsu Amanda
  • 31
  • 6
  • 1
    it is the correct way to use `1>`, Windows helpfully puts it in if you forget. See http://stackoverflow.com/questions/41030190/command-to-run-a-bat-file/41049135#41049135 – Noodles May 30 '19 at 06:48
  • Please read Microsoft's documentation about [Using command redirection operators](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490982(v=technet.10)) and DosTips forum topic: [ECHO. FAILS to give text or blank line - Instead use ECHO/](https://www.dostips.com/forum/viewtopic.php?f=3&t=774). On using in a batch file with just `>` or `>>` to redirect standard output to a file or a device like __NUL__ without `@echo off` the Windows command processor shows the line how it is executed after parsing it. You can see that a space and `1` is inserted left to `>`. – Mofi May 30 '19 at 18:58
  • That is normal and nothing which you must worry about. It is not recommended to write in a batch file `1>` or `1>>` although possible. In some cases specifying explicitly handle number `1` left to redirection operator can result in unexpected behavior. So it is good practice to not write handle number `1` left to `>` and `>>` in a batch file. See also [Why does ECHO command print some extra trailing space into the file?](https://stackoverflow.com/a/46972524/3074564) and [How does the Windows Command Interpreter (CMD.EXE) parse scripts?](https://stackoverflow.com/questions/4094699/) – Mofi May 30 '19 at 18:58
  • thanks for your answer in detail, i would try to do more practice! – Hsu Amanda May 31 '19 at 03:35

0 Answers0