[gs-bugs] [Bug 691440] Windows bat files use relative paths and write to non-temp dir

bugzilla-daemon at ghostscript.com bugzilla-daemon at ghostscript.com
Tue Jul 27 19:31:35 UTC 2010


SaGS <sags5495 at hotmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |sags5495 at hotmail.com

--- Comment #5 from SaGS <sags5495 at hotmail.com> 2010-07-27 19:31:33 UTC ---
There are a few problems with the adopted solution, and I will suggest 2 
patches for fixing them.

Patch order: the 2 patches are ‘successive’, in comment order. Please 
apply them in this order, otherwise patch won’t find the context it needs. 
There are hunks in the 1st patch that apply with a fuzz factor, that’s OK; 
the reasons are the ‘$Id$’s, patch does not know to un-expand them.

(A) %~dp0 does not work on Win95/98/ME, only on the NT-based versions

This is already mentioned in comments above. Fortunately there is an easy 
way to rectify the situation, so no need to cut off old Windows versions.

The technique used: ‘%0\..’ is the absolute/relative directory of the 
batch file, as specified by the user on the command line. The ‘..\’ removes 
the path component that precedes it, in this case the bat filename itself; 
it is not necessary for the respective component to represent an actual 
directory, it can be a file or not exist at all.

There is only one case when this does not work directly and has to be 
handled specially: if the user started the bat by typing its filename 
without any path AND the *.bat is not in the current directory. In this 
case (and only in this case) the command interpreter searches the %PATH%. 
The case is detected by ‘if not exist %0\..\self.bat’, and no path will 
be specified for subordinate batch files, so the command interpreter will 
be able to search them in the %PATH% the same as it did for the main bat.

(B) Temp files are (usually) written near, not inside, %TEMP%

With a default Windows installation, %TEMP% is set but without a trailing 
backslash. So ‘%TEMP%_at’ can be, for example, placed in the directory 
‘C:\Document and Settings\user\Local Settings’ and named ‘TEMP_at’.

The solution: use ‘%TEMP%.\_at’ instead. Here is how this works:

  - case 1: %TEMP% not set
    ‘%TEMP%.\_at’ becomes ‘.\_at’. Temp files are created in the current 
    directory as before.

  - case 2: %TEMP% set without a trailing ‘\’, for example ‘C:\TEMP’
    ‘%TEMP%.\_at’ becomes, for example, ‘C:\TEMP.\_at’. This is the same 
    as ‘C:\TEMP\_at’, because Windows IGNORES trailing periods.

  - case 3: %TEMP% set with a trailing ‘\’, for example ‘C:\TEMP\’
    ‘%TEMP%.\_at’ becomes, for example, ‘C:\TEMP\.\_at’, OK.

(C) A typo: a ‘>>’ was suppressed from ps2pdf.bat

    Modified: trunk/gs/lib/ps2pdf.bat
    --- trunk/gs/lib/ps2pdf.bat    2010-07-08 20:01:59 UTC (rev 11497)
    +++ trunk/gs/lib/ps2pdf.bat    2010-07-09 09:40:17 UTC (rev 11498)
    @@ -6,13 +6,13 @@
    -echo %1 >>_.at
    +echo %1 %TEMP%_.at       <== HERE

(D) It’s not impossible (but a bad idea) for %TEMP% to contain spaces

I noticed Windows to define %TEMP% using DOS 8.3 names by default. However, 
it is possible the user does differently, and also it’s possible to 
completely disable the creation of DOS 8.3 aliases on disk.

Configure bugmail: http://bugs.ghostscript.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the gs-bugs mailing list