Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#1
Post
by Docfxit » 08 Mar 2023 12:49
Something is wrong with my syntax.
I have some code:
Code: Select all
systeminfo | findstr /B "OS Name:" >>"%~dpn0.txt"
systeminfo | findstr /B "OS Version:" >>"%~dpn0.txt"
The output in the txt file shows:
Code: Select all
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19045 N/A Build 19045
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19045 N/A Build 19045
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
What I expect it to show is:
Code: Select all
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19045 N/A Build 19045
What could I be doing wrong?
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#2
Post
by ShadowThief » 09 Mar 2023 00:10
When you don't use the /C flag, then findstr takes everything in quotes to be a list of things to search for. findstr /B "OS Name:" tells findstr to look for both "OS" and "Name:"
Code: Select all
systeminfo | findstr /B /C:"OS Name:" >>"%~dpn0.txt"
systeminfo | findstr /B /C:"OS Version:" >>"%~dpn0.txt"
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#3
Post
by Docfxit » 09 Mar 2023 18:55
Thank you very much.
That's great to know.
It's very nice of you to share your knowledge.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 05 Dec 2023 12:11
Docfxit wrote: ↑09 Mar 2023 18:55
Thank you very much.
That's great to know.
It's very nice of you to share your knowledge.
Straight from the help file for the findstr command.
Code: Select all
Use spaces to separate multiple search strings unless the argument is prefixed
with /C.
I have seen a pattern with some of your questions and it seems like often you do not read the help file for the command you are using.