Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why use findstr to create an empty file on Windows? #3

Closed
b- opened this issue Dec 18, 2020 · 1 comment
Closed

Why use findstr to create an empty file on Windows? #3

b- opened this issue Dec 18, 2020 · 1 comment
Labels

Comments

@b-
Copy link

b- commented Dec 18, 2020

I was perusing the code here after seeing this on lobste.rs, and I was very confused by the following line,

vimer/vimer.cmd

Line 185 in 23a5246

findstr "^" > "%stdin_file%"

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.

@susam susam added the question label Dec 18, 2020
@susam
Copy link
Owner

susam commented Dec 18, 2020

The command findstr "^" > "%stdin_file%" mimics the behaviour of cat > "$stdin_file" on Unix. Compare

vimer/vimer.cmd

Line 185 in 23a5246

findstr "^" > "%stdin_file%"
with

vimer/vimer

Line 170 in 23a5246

cat > "$stdin_file"
to see the similarity.

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

@susam susam closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants