Skip to content

Debugging a script that invokes exiftool.exe hangs #3225

Closed

Description

System Details

System Details Output

### VSCode version: 1.53.2 622cb03f7e070a9670c94bae1a45d78d7181fbd4 x64

### VSCode extensions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]


### PSES version: 2.3.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

When I run the following script under the PowerShell debugger within VScode, it hangs when launching exiftool.exe:

$exiftool = (Get-Command exiftool).Path
Write-Host ("'exiftool' is '{0}' (version {1}) {{MD5={2}}}" -f $exiftool, (Get-Item $exiftool).VersionInfo.ProductVersion, (Get-Filehash -Algorithm MD5 $exiftool).Hash)
$cmd = "{0} -DateTimeOriginal {1}" -f $exiftool, (Join-Path -Path $PSScriptRoot -ChildPath 'foobar.cr2')
Write-Host ("Invoking '{0}'" -f $cmd)
Invoke-Expression $cmd

Expected Behaviour

When running outside of the debugger (in a standalone PowerShell session, or in the VScode terminal), I get the expected results:

'exiftool' is 'c:\usr\wbin\exiftool.exe' (version 12.2.1.0) {MD5=4ECB5A8B4AA893F3ADFD48E8ACEBC669}
Invoking 'c:\usr\wbin\exiftool.exe -DateTimeOriginal S:\powershell\test\foobar.cr2'
Date/Time Original              : 2019:12:25 16:36:30

Actual Behaviour

When run via the debugger (F5 in VScode) the script hangs:

'exiftool' is 'c:\usr\wbin\exiftool.exe' (version 12.2.1.0) {MD5=4ECB5A8B4AA893F3ADFD48E8ACEBC669}
Invoking 'c:\usr\wbin\exiftool.exe -DateTimeOriginal S:\powershell\test\foobar.cr2'

Here's the version of exiftool.exe on my system:

exiftool.zip

Attached Logs

1614863299-c8495592-f210-48e1-a203-cc687e42687b1614861694455 - Copy.zip

Activity

  1. ghost added
    Needs: Triage
    on Mar 4, 2021
  2. rjmholt commented on Mar 4, 2021

    @rjmholt
    Contributor

    This may well be a duplicate of #2559.

    We did some investigation around that issue but weren't able to determine why exiftool.exe specifically interacts badly with the Integrated Console. Unfortunately, we're not likely to be able to prioritise such a specific bug before other issues we're currently working toward.

  3. sba923 commented on Mar 4, 2021

    @sba923
    Author

    Even if not a exact duplicate this does look like it's a very close issue.

    I was so convinced this could not be specific to exiftool that I didn't bother searching for that in the existing issues 😜

    I do understand that this is very specific and thus low priority.

    I'll start looking for workarounds... (all my photo/video related tooling relies on exiftool to extra e.g. the 'date taken' from DSLR RAW images...)

  4. rjmholt commented on Mar 4, 2021

    @rjmholt
    Contributor

    Honestly I'm perplexed as to why this occurs with exiftool. I did look into it with the last issue but couldn't see a good reason (it's basically a self-contained Perl script right?).

    Anyway, if it's a bad PSReadLine interaction due to the idiosyncrasies of the Integrated Console, it might be something we can mitigate as we rework the integrated console.

  5. removed
    Needs: Triage
    on Mar 9, 2021
  6. sba923 commented on Dec 27, 2021

    @sba923
    Author

    As I had to work on my picture/video management scripts during the holidays, I was hit by this issue once again.

    Would there be a way to detect that a script is running under the debugger, so that it could be prevented from running there? This way I would just be reminded that I must run the script outside of VScode?

  7. JustinGrote commented on Jan 24, 2022

    @JustinGrote
    Collaborator

    Stéphane BARIZIEN (@sba923) yes, you can
    $env:TERM_PROGRAM -eq 'vscode'

  8. ghost added
    Needs: Maintainer Attention
    on Jan 24, 2022
  9. sba923 commented on Apr 4, 2022

    @sba923
    Author

    $env:TERM_PROGRAM -eq 'vscode'

    I confirm this works, so I'm spreading this all around 😥

    if ($env:TERM_PROGRAM -eq 'vscode')
    {
        Write-Host -ForegroundColor Red ("This script uses 'exiftool'. It will hang if invoked from VScode.")
        Exit(1)
    }

    Anything I could do to help getting rid of this issue?

  10. SeeminglyScience commented on Apr 4, 2022

    @SeeminglyScience
    Collaborator

    Can you try just pressing any key when it appears stuck? Make sure the terminal is focused (click somewhere inside it) and just press enter. Please let me know if it continues after that.

  11. sba923 commented on Apr 4, 2022

    @sba923
    Author

    yes it does continue, even after pressing Space or even a!!!

  12. SeeminglyScience commented on Apr 4, 2022

    @SeeminglyScience
    Collaborator

    Yeah that checks out. I think I know what's up, we'll get it fixed if it is what I think.

  13. 5 remaining items

  14. moved this from Todo to In Progress in Sea Biscuiton Apr 12, 2022
  15. andyleejordan commented on Apr 12, 2022

    @andyleejordan
    Member

    Hi there, we just released v2022.4.0-preview! Could you please try PowerShell Preview for VS Code and verify this is fixed?

  16. sba923 commented on Apr 13, 2022

    @sba923
    Author

    Hi,

    What I get with

    $exiftool = (Get-Command exiftool).Path
    Write-Host ("'exiftool' is '{0}' (version {1}) {{MD5={2}}}" -f $exiftool, (Get-Item $exiftool).VersionInfo.ProductVersion, (Get-Filehash -Algorithm MD5 $exiftool).Hash)
    $exiftool_args = @('-DateTimeOriginal', (Join-Path -Path $PSScriptRoot -ChildPath 'foobar.cr2'))
    Write-Host ("Invoking '{0} {1}'" -f $exiftool, ($exiftool_args -join ' '))
    & $exiftool @exiftool_args

    is:

    1. no more hanging
    2. VScode terminal shows a à upon execution -- seems the readline gets a dummy character from somewhere...

    image

  17. andyleejordan commented on Apr 13, 2022

    @andyleejordan
    Member

    Yay! Then this is resolved. I'm aware of the dummy character, there's a race inside PSReadLine that we need to resolve with that project, and so right now we send a dummy character that's just:

            private static readonly ConsoleKeyInfo s_nullKeyInfo = new(
                keyChar: ' ',
                ConsoleKey.DownArrow,
                shift: false,
                alt: false,
                control: false);
    

    Which should be a no-op (but clearly isn't, as you're getting an accented a, and another person is getting a quote).

  18. added
    Resolution-Fixed
    and removed
    Needs: Fix Verification
    on Apr 13, 2022
  19. moved this from In Progress to Done in Sea Biscuiton Apr 13, 2022
  20. ghost closed this as completedon Apr 13, 2022
  21. sba923 commented on May 4, 2022

    @sba923
    Author

    Yay! Then this is resolved. I'm aware of the dummy character, there's a race inside PSReadLine that we need to resolve with that project, and so right now we send a dummy character that's just:

            private static readonly ConsoleKeyInfo s_nullKeyInfo = new(
                keyChar: ' ',
                ConsoleKey.DownArrow,
                shift: false,
                alt: false,
                control: false);
    

    Which should be a no-op (but clearly isn't, as you're getting an accented a, and another person is getting a quote).

    Can you please confirm this (the dummy character) is fixed with version 2022.5.0 of the extension and PSReadLine 2.2.5?

  22. andyleejordan commented on May 4, 2022

    @andyleejordan
    Member

    Can you please confirm this (the dummy character) is fixed with version 2022.5.0 of the extension and PSReadLine 2.2.5?

    Yes indeed it is!

  23. sba923 commented on May 4, 2022

    @sba923
    Author

    Can you please confirm this (the dummy character) is fixed with version 2022.5.0 of the extension and PSReadLine 2.2.5?

    Yes indeed it is!

    Good news! This means I'll no longer need to use the workaround

    $result = '' | & $exiftool @exiftool_args

    and will be able to use the standard construct instead:

    $result = & $exiftool @exiftool_args

    Thanks again for the fix. I've been patient 😜.

  24. andyleejordan commented on May 4, 2022

    @andyleejordan
    Member

    Very patient. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-DebuggingIssue-BugResolution-Fixed

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions