Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I make my environment variable (set in batch file) visible in application executed right after setting this envvar?

Here's the scenario that I use:

  1. In my external script (not quite important here) I create Windows shortcuts to jpg files, with the target looking like:

    %MYPHOTOSDRIVE%:\private\photos\photo001.jpg
    

    %MYPHOTODRIVE% should contain just a current drive letter.

  2. I start IrfanView using the following BAT script (script is located in the same directory as all the .lnk files):

    set MYPHOTOSDRIVE=%cd:~0,2%
    "c:\Program Files\IrfanView\i_view32.exe" "i:\private\photolinks\photo001.lnk"
    "c:\Program Files\IrfanView\i_view32.exe" /slideshow="%cd%"
    

The problem is that neither the single image, nor a slideshow (for the second call to IrfanView) is executed properly.

Shouldn't this "MYPHOTODRIVE" variable be expanded to a proper value upon Irfan execution? Doesn't it get the same environment as the parent script?

share|improve this question
    
(1) Look at the Properties dialog for your picture shortcuts. Do they still have %MYPHOTOSDRIVE%? If that variable is not set globally (for all of Windows, not just a single console instance), then Explorer does not use it. (2) Try adding a line after the set like echo %%MYPHOTOSDRIVE%% to see if it is correct. (3) I don’t think IrfanView can take a shortcut; it won’t resolve automatically. –  Synetech Feb 6 '12 at 1:08
    
*1 Yes, all picture shortcuts have %MYPHOTOSDRIVE% instead of a drive letter. *2 Env. variable is set properly when I check it this way. *3 I was hoping that it would work the same as it does when calling another batch script from the first one. In this case this variable would be expanded to a proper value... –  schedar Feb 6 '12 at 1:13

1 Answer 1

up vote 0 down vote accepted

The problem is that you are not passing an environment variable to IrfanView eg:

C:\> i_view32.exe %%myphotosdrive%%:\private\photos\photo001.jpg

You are passing it a .LNK file (which is binary). IrfanView does not know how to interpret shortcut files; it only handles graphics files and such.

Your best bet is to request that Irfan add the ability to resolve shortcut files (he is quite responsive and good at handling support questions and feature requests).

share|improve this answer
    
You're right. I've created a request here: irfanview-forum.de/… –  schedar Feb 6 '12 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.