Question about using PowerShell Select-String, exiftool(-k)

前端 未结 2 467
北荒
北荒 2021-01-15 02:43

In a PowerShell script I\'m trying to filter the output of the exiftool(-k).exe command below, using Select-String.

I\'ve tried numerous

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 03:06

    • You cannot directly receive output from a Start-Process call[1], so using it in a pipeline is pointless.

      • In fact, on Windows your program launched with Start-Process runs in a different, new window, which is where you saw the unfiltered output (given that no Select-String was applied there); in your calling window, Start-Process produced no output at all, and therefore nothing was sent to Select-String, and the pipeline as a whole produced no output.
    • Never use Start-Process to synchronously invoke a console application whose output you want to capture or redirect - simply call the application directly:

    & "C:\PowerShell\exiftool(-k).exe" test.jpg | Select-String GPS -SimpleMatch
    

    Note that &, the call operator, is needed for this invocation, because your executable path is (double-)quoted (of necessity here, because the file name contains ( and )); & is only needed for executable paths that are quoted and/or contain variable references; you wouldn't need it to call git ..., for instance.


    [1] While you would see the program's output in the caller's window if you added -NoNewWindow -Wait to a Start-Process call, you still wouldn't be able to capture, pass on or redirect it.

提交回复
热议问题