0

i'm getting an error of "FIND: Parameter format not correct" in powershell

The following works from CMD

C:\Users\User>echo abc | find "a"
abc

C:\Users\User>echo abc>z.z

C:\Users\User>find "a" z.z

---------- Z.Z
abc

C:\Users\User>

But this fails from powershell!

PS C:\Users\User> echo abc | find "a"
FIND: Parameter format not correct
PS C:\Users\User> echo abc >z.z
PS C:\Users\User> find "a" z.z
FIND: Parameter format not correct
PS C:\Users\User>

There is a similar question here "FIND: Parameter format not correct" and "FINDSTR: Write error" with Pipes where the answer says to use quotation marks with the find command. Though I have And I wouldn't be using /C because i'm not trying to count occurrences. Though find /c isn't working either

PS C:\Users\User> find /C "a" z.z
FIND: Parameter format not correct
PS C:\Users\User>

And it's not a UK keyboard issue, where two pipe characters get swapped. 'cos it works in cmd and not powershell. And I tried copy/pasting the correct pipe character from charmap. And as yo see this occurs also with the format of find [pattern] file. So without any pipe. So, not a pipe issue.

There's something about powershell and find, that is going wrong here. Where cmd is fine.

Added

Upon further investigation

PS C:\Users\User> which find
/cygdrive/c/Windows/system32/find
PS C:\Users\User>

Makes me wonder, is that a PATH problem it's clashing with cygwin?

I don't think it's a PATH problem, because that's just cygwin's way of stating that the path is in c:\windows\system32 but does look like a weird clash with cygwin though in some way.. not sure if relevant to the problem.

It is running windows FIND

PS C:\Users\User> find /?
Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  /V         Displays all lines NOT containing the specified string.
  /C         Displays only the count of lines containing the string.
  /N         Displays line numbers with the displayed lines.
  /I         Ignores the case of characters when searching for the string.
  /OFF[LINE] Do not skip files with offline attribute set.
  "string"   Specifies the text string to find.
  [drive:][path]filename
             Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
PS C:\Users\User>
barlop
  • 23,380
  • 43
  • 145
  • 225

1 Answers1

3

This works fine:

write-host "abc" | find "`"a`""

In Powershell, its better using Select-String:

Write-host "abc" | Select-String "a"
Wasif
  • 7,984
  • 2
  • 19
  • 32
  • thanks, and this worked with your quoting `echo abc | find "\`"a\`""` can you explain what's going on there?! – barlop Sep 26 '20 at 16:17
  • Cmd.exe and Powershell.exe renders and executes the command differently, while in Powershell quotes don't get applied – Wasif Sep 26 '20 at 16:18
  • alright but what does the backtick thing do exactly.. so you have `\`"a\`"` (and then that strange thing , in double quotes `"\`"a\`""` – barlop Sep 26 '20 at 16:20
  • 1
    Backtick escapes the double quote inside another double quote – Wasif Sep 26 '20 at 16:39
  • but why does `dir "a.a"` work (with unescaped double quotes), and `echo "aa"` works(with unescaped double quotes). But not find with unescaped double quotes? – barlop Sep 26 '20 at 16:47
  • 1
    There those double quotes are not enclosed inside another double quotes, so they don't need escaping – Wasif Sep 26 '20 at 16:50
  • thanks, but why would I even need two sets of double quotes, to use find in powershell?! – barlop Sep 26 '20 at 16:57
  • Your select-string line doesn't really seem to work because `Write-host "abc" | Select-String "z"` outputs the same as `Write-host "abc" | Select-String "a"`. Both output `abc` – barlop Sep 26 '20 at 20:02