how strings in pipe?

Chuck Kollars 1 Reputation point
2022-09-05T20:05:34.197+00:00

How do you tell a tool (for example strings.exe) to read its input from "stdin" rather than from a file? (I dimly remember the convention on Unix being specify a minus sign in the place where a filename would usually go, but something like "curl ... | strings -" doesn't work.) The Windows Cmd box prompt understands the pipe symbol ( | ) and does the right thing with it ...and I'd like to be able to use sysinternals tools in a pipe. How can I tell the tools where to look for their input (stdin rather than a file)?

Sysinternals
Sysinternals
Advanced system utilities to manage, troubleshoot, and diagnose Windows and Linux systems and applications.
1,086 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 31,571 Reputation points
    2022-09-06T02:06:19.797+00:00

    Find and findstr work, but strings appears to be looking for a file name.

    C:\Temp>type cmdLogs.txt | find "Apps"  
    11/04/2021  06:10 PM    <DIR>          Apps  
      
    C:\Temp>type cmdLogs.txt | findstr "Apps"  
    11/04/2021  06:10 PM    <DIR>          Apps  
      
    C:\Temp>type cmdLogs.txt | strings "Apps"  
      
    Strings v2.53 - Search for ANSI and Unicode strings in binary images.  
    Copyright (C) 1999-2016 Mark Russinovich  
    Sysinternals - www.sysinternals.com  
      
    No matching files were found.  
    

    Note the last sentence.

    C:\Temp>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.  
    

    Depending on what you are trying to do, Powershell's Select-String might be an alternative.

    0 comments No comments

  2. Chuck Kollars 1 Reputation point
    2022-09-06T03:49:56.98+00:00

    As you note, most Microsoft Windows tools understand stdin. The Unix version of strings understood stdin. The Linux version of strings understands stdin. The old MKS Toolkit version of strings that ran on WindowsNT understands stdin. Why doesn't the sysinternals version of strings understand stdin (apparently not even with hacked-up syntax)?

    (Obviously, I'm not impressed by the "it's documented, therefore it will never happen" reasoning; it's a slippery slope to 'documenting' flat-out bugs and then not addressing them.
    My use is part of a large complex system that was created before Powershell even existed, and I'm not enthusiastic about spending weeks porting everything now.)