Issue:
IrfanView command line processing produces inconsistently weird results
How to reproduce:
1. Create a file, call it "c:\a.jpg" (preferably a valid jpg image, but that isn't really required; doesn't have to be at C: drive)
2. Create a file, call it "c:\b.jpg" (preferably a valid jpg image, but that isn't really required; should be visually different from the "a.jpg" file, just so that you can tell them apart; doesn't have to be at C: drive, but has to be at the same drive as "a.jpg")
3. Make sure IrfanView is located in a directory that does NOT have any spaces in its full path (i.e. not in "Program Files"). I know that people *typically* install in "Program Files", but that shouldn't be a hard requirement.
4. Paste this C code into a file:
5. Replace "C:\\IrfanView\\" with your IrfanView directory (with backslashes).
6. Replace "C:/IrfanView/" with your IrfanView directory (with forward slashes)
7. Replace "C:\\b.jpg" with your own path to "b.jpg" (with backslashes)
8. Replace "C:/b.jpg" with your own path to "b.jpg" (with forward slashes)
9. Compile the program
10. Run the program repeatedly, with the first argument being a number between '1' and '9', then a letter between 'a' and 'w' (I know it's stupid, but this is a test case, not an end-user program; I coded the simplest argument parsing I could come up with).
The program runs i_view32.exe to open the file b.jpg, with various command line variations (forward slashes, back slashes in either or both arguments; quotes around either or both arguments, single or double space between arguments).
Expected result:
* Each and every invocation results in IrfanView running and opening b.jpg
Actual result:
* Some invocations open a.jpg instead (apparently, IrfanView opens "c:" drive and picks the first file it finds, which is "a.jpg")
Windows 10 20H2, IrfanView 4.56 32-bit
IrfanView command line processing produces inconsistently weird results
How to reproduce:
1. Create a file, call it "c:\a.jpg" (preferably a valid jpg image, but that isn't really required; doesn't have to be at C: drive)
2. Create a file, call it "c:\b.jpg" (preferably a valid jpg image, but that isn't really required; should be visually different from the "a.jpg" file, just so that you can tell them apart; doesn't have to be at C: drive, but has to be at the same drive as "a.jpg")
3. Make sure IrfanView is located in a directory that does NOT have any spaces in its full path (i.e. not in "Program Files"). I know that people *typically* install in "Program Files", but that shouldn't be a hard requirement.
4. Paste this C code into a file:
Code:
#include <windows.h> #include <stdio.h> #define BSLASH_IVIEW "c:\\IrfanView\\i_view32.exe" #define BSLASH_FILE "c:\\b.jpg" #define FSLASH_IVIEW "c:/IrfanView/i_view32.exe" #define FSLASH_FILE "c:/b.jpg" int main (int argc, char **argv) { char *cmdline; BOOL b; STARTUPINFOA sa; PROCESS_INFORMATION pi; if (argc < 2) return 1; if (argv[1][0] == '1') cmdline = BSLASH_IVIEW " " BSLASH_FILE; else if (argv[1][0] == '2') cmdline = BSLASH_IVIEW " " FSLASH_FILE; else if (argv[1][0] == '3') cmdline = FSLASH_IVIEW " " BSLASH_FILE; else if (argv[1][0] == '4') cmdline = FSLASH_IVIEW " " FSLASH_FILE; else if (argv[1][0] == '5') cmdline = "\"" BSLASH_IVIEW "\" " BSLASH_FILE; else if (argv[1][0] == '6') cmdline = "\"" BSLASH_IVIEW "\" " FSLASH_FILE; else if (argv[1][0] == '7') cmdline = "\"" FSLASH_IVIEW "\" " BSLASH_FILE; else if (argv[1][0] == '8') cmdline = "\"" FSLASH_IVIEW "\" " FSLASH_FILE; else if (argv[1][0] == '9') cmdline = BSLASH_IVIEW " \"" BSLASH_FILE "\""; else if (argv[1][0] == 'a') cmdline = BSLASH_IVIEW " \"" FSLASH_FILE "\""; else if (argv[1][0] == 'b') cmdline = FSLASH_IVIEW " \"" BSLASH_FILE "\""; else if (argv[1][0] == 'c') cmdline = FSLASH_IVIEW " \"" FSLASH_FILE "\""; else if (argv[1][0] == 'd') cmdline = "\"" BSLASH_IVIEW "\" \"" BSLASH_FILE "\""; else if (argv[1][0] == 'e') cmdline = "\"" BSLASH_IVIEW "\" \"" FSLASH_FILE "\""; else if (argv[1][0] == 'f') cmdline = "\"" FSLASH_IVIEW "\" \"" BSLASH_FILE "\""; else if (argv[1][0] == 'g') cmdline = "\"" FSLASH_IVIEW "\" \"" FSLASH_FILE "\""; else if (argv[1][0] == 'h') cmdline = BSLASH_IVIEW " " BSLASH_FILE; else if (argv[1][0] == 'i') cmdline = BSLASH_IVIEW " " FSLASH_FILE; else if (argv[1][0] == 'j') cmdline = FSLASH_IVIEW " " BSLASH_FILE; else if (argv[1][0] == 'k') cmdline = FSLASH_IVIEW " " FSLASH_FILE; else if (argv[1][0] == 'l') cmdline = "\"" BSLASH_IVIEW "\" " BSLASH_FILE; else if (argv[1][0] == 'm') cmdline = "\"" BSLASH_IVIEW "\" " FSLASH_FILE; else if (argv[1][0] == 'n') cmdline = "\"" FSLASH_IVIEW "\" " BSLASH_FILE; else if (argv[1][0] == 'o') cmdline = "\"" FSLASH_IVIEW "\" " FSLASH_FILE; else if (argv[1][0] == 'p') cmdline = BSLASH_IVIEW " \"" BSLASH_FILE "\""; else if (argv[1][0] == 'q') cmdline = BSLASH_IVIEW " \"" FSLASH_FILE "\""; else if (argv[1][0] == 'r') cmdline = FSLASH_IVIEW " \"" BSLASH_FILE "\""; else if (argv[1][0] == 's') cmdline = FSLASH_IVIEW " \"" FSLASH_FILE "\""; else if (argv[1][0] == 't') cmdline = "\"" BSLASH_IVIEW "\" \"" BSLASH_FILE "\""; else if (argv[1][0] == 'u') cmdline = "\"" BSLASH_IVIEW "\" \"" FSLASH_FILE "\""; else if (argv[1][0] == 'v') cmdline = "\"" FSLASH_IVIEW "\" \"" BSLASH_FILE "\""; else if (argv[1][0] == 'w') cmdline = "\"" FSLASH_IVIEW "\" \"" FSLASH_FILE "\""; else return 2; memset (&sa, 0, sizeof (sa)); sa.cb = sizeof (sa); b = CreateProcessA (NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &sa, &pi); if (!b) printf ("ERROR: %ld\n", GetLastError ()); return 0; }
6. Replace "C:/IrfanView/" with your IrfanView directory (with forward slashes)
7. Replace "C:\\b.jpg" with your own path to "b.jpg" (with backslashes)
8. Replace "C:/b.jpg" with your own path to "b.jpg" (with forward slashes)
9. Compile the program
10. Run the program repeatedly, with the first argument being a number between '1' and '9', then a letter between 'a' and 'w' (I know it's stupid, but this is a test case, not an end-user program; I coded the simplest argument parsing I could come up with).
The program runs i_view32.exe to open the file b.jpg, with various command line variations (forward slashes, back slashes in either or both arguments; quotes around either or both arguments, single or double space between arguments).
Expected result:
* Each and every invocation results in IrfanView running and opening b.jpg
Actual result:
* Some invocations open a.jpg instead (apparently, IrfanView opens "c:" drive and picks the first file it finds, which is "a.jpg")
Windows 10 20H2, IrfanView 4.56 32-bit
Comment