Fixing Exiftool In Double Commander On Windows
Understanding the exiftool.exe and Double Commander Conflict
Many Windows users have encountered a frustrating issue: exiftool.exe functions perfectly fine when run directly from the Windows Terminal or Command Prompt, but fails to deliver results within Double Commander. This often manifests as multiple command prompt windows briefly flashing on the screen, followed by Double Commander displaying blank information instead of the expected metadata output. This behavior suggests that the core exiftool.exe itself isn't the problem, but rather how Double Commander interacts with external command execution and output capture. The situation is further complicated by the fact that even after properly configuring the system environment variables and restarting the computer, the issue persists, making it seem like the core problem lies in Double Commander and its plugin integration rather than a simple configuration error. Furthermore, both installation packages and portable packages of Double Commander were tested, which shows that the problem is not related to the Double Commander package.
The Core Problem
The core issue stems from how Double Commander handles the execution of external commands and the subsequent capture of their output. Double Commander, unlike the terminal, may not be correctly capturing the output or properly handling the command's execution environment. This can lead to the observed behavior of flashing command prompt windows and empty results. The exiftoolwdx.lua plugin, designed to integrate ExifTool metadata reading into Double Commander, relies on the correct execution and output parsing of exiftool.exe. When this process fails, the plugin cannot retrieve the desired metadata, thus resulting in the missing information.
Analyzing the exiftoolwdx.lua Script
The provided exiftoolwdx.lua script is designed to interface with exiftool.exe, extract metadata from files, and display it within Double Commander. Let's break down the key parts of this script and identify potential areas of concern.
Script Breakdown
The script defines several key elements:
cmd = "exiftool": Specifies the command to execute (ExifTool).debug_log = "C:\\SSS\\doublecmd\\scripts\\lua\\exiftool_debug.log": Defines a debug log file for troubleshooting.fields: An array that defines the metadata fields to extract, and their corresponding data types (string, number, date).ContentGetSupportedField(FieldIndex): Returns the name, unit, and type of a supported field.ContentGetDetectString(): Returns the file extension pattern that the plugin should recognize.ContentGetValue(FileName, FieldIndex, UnitIndex, flags): This is the core function, that executesexiftool.exe, captures the output, and parses the metadata.getval(str, fieldtype): This function extracts specific metadata values from the output ofexiftool.exebased on the field type.escapestr(str): This function ensures that special characters in the file name are properly escaped before passing them toexiftool.exe.test_exiftool(): Tests for the availability of Exiftool by runningexiftool -verand checking the output. This is crucial for identifying if Exiftool is accessible from the script's execution context.
Debugging with debug_log
The script utilizes a debug_log to record the events and the output of the script execution. This allows a user to monitor the behavior of the script in Double Commander.
Troubleshooting Steps and Solutions
To effectively resolve this issue, we will delve into debugging and apply targeted solutions. Here's a structured approach:
1. Verify ExifTool's Accessibility Within Double Commander
The most common cause of this problem is that Double Commander is not correctly accessing exiftool.exe. We can verify the execution of Exiftool from Double Commander.
- Check the
debug_log: The providedexiftool_debug.logis a crucial resource. If ExifTool is not accessible, the log file will show an error during thetest_exiftool()call, indicating a path or environment variable issue. - Environment Variables: Double-check that the directory containing
exiftool.exeis included in thePATHenvironment variable. This is essential for the script to find and execute the tool. - Double Commander's Context: Ensure Double Commander is restarted after making changes to the environment variables. This is crucial for the changes to take effect within Double Commander.
2. Examine the Command Execution within the Script
The script uses io.popen() to execute the exiftool.exe command. The way the command is constructed and the output is handled could be problematic.
- Command Construction: Ensure the file name passed to
exiftool.exeis correctly quoted and escaped within the script. - Output Handling:
io.popen()opens a pipe to the command's output. The script then reads the entire output usinghandle:read("*a"). Make sure that the script correctly captures the output. Problems in this area can lead to empty results or errors.
3. Diagnose the Flashing Windows
The flashing command prompt windows are a common symptom of a problem in command execution.
- Command Prompt Settings: Double Commander itself might have settings related to how it handles external command executions. Check Double Commander's configuration for options that control command-line behavior.
- Permissions: Make sure the user account running Double Commander has the necessary permissions to execute
exiftool.exeand access the files. In rare cases, insufficient permissions can cause execution failures.
4. Code Review and Modification
- Error Handling: Enhance the script to include more robust error handling. For instance, check the return value of
io.popen()to ensure the command executed successfully. Ifio.popen()fails, log an error message to the debug log. - Output Parsing: The script parses the output of
exiftool.exeusing string matching. If the output format ofexiftool.exeis not as expected, the parsing will fail. Verify the expected output format of Exiftool and adjust thegetvalfunction to correctly extract the metadata.
Example: Enhanced Error Handling
Here's an example of how you can enhance the Lua script with error handling:
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
log_debug("=== ContentGetValue: " .. FileName .. " ===")
if not test_exiftool() then
log_debug("Exiftool not available, skipping")
return nil
end
if (filename ~= FileName) then
local attr = SysUtils.FileGetAttr(FileName);
if (attr < 0) or (math.floor(attr / 0x00000004) % 2 ~= 0) or (math.floor(attr / 0x00000010) % 2 ~= 0) then
return nil;
end
local handle = io.popen(cmd .. ' "' .. FileName:gsub('"', '\"') .. '"', 'r');
if handle then
output = handle:read("*a");
handle:close();
if output == nil or output == "" then
log_debug("Error: Exiftool returned no output.")
return nil
end
else
log_debug("Error: Failed to execute Exiftool.")
return nil
end
filename = FileName;
end
return getval(fields[FieldIndex + 1][1], fields[FieldIndex + 1][2]);
end
Conclusion: Solving the ExifTool Integration in Double Commander
By following the described troubleshooting steps, analyzing the Lua script, and implementing robust error handling, you can successfully integrate exiftool.exe with Double Commander. Remember to pay close attention to environment variables, command execution, output handling, and error logging to pinpoint and resolve any issues. This approach will allow you to access the detailed metadata of your files directly within Double Commander, enhancing your file management experience.
For more information on Double Commander plugins, you can visit the Double Commander Plugin Documentation.