Why use `findstr` to create an empty file on Windows?
b- opened this issue · comments
I was perusing the code here after seeing this on lobste.rs, and I was very confused by the following line,
Line 185 in 23a5246
I don’t have a Windows computer handy to see if there’s anything going on that I’m missing, but based on the comment it sounds like this just creates an empty file, a la touch
on *nix. If this indeed is what’s going on, copy nul > file
is a more supported (and potentially faster) way to do just that.
The command findstr "^" > "%stdin_file%"
mimics the behaviour of cat > "$stdin_file"
on Unix. Compare
Line 185 in 23a5246
Line 170 in 23a5246
Here is an example on Windows:
C:\>echo hello | findstr "^"
hello
C:\>echo hello | findstr "^" > out.txt
C:\>type out.txt
hello
Here is a similar example on Unix:
$ echo hello | cat
hello
$ echo hello | cat > out.txt
$ cat out.txt
hello