Page 1 of 1

My syntax is not correct

Posted: 08 Mar 2023 12:49
by Docfxit
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?

Re: My syntax is not correct

Posted: 09 Mar 2023 00:10
by ShadowThief
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"

Re: My syntax is not correct

Posted: 09 Mar 2023 18:55
by Docfxit
Thank you very much.

That's great to know.
It's very nice of you to share your knowledge.

Re: My syntax is not correct

Posted: 05 Dec 2023 12:11
by Squashman
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.