On Wednesday 07 December 2005 23:20, Uwe Stöhr wrote:
> I investigated a bit and the problem seems to be the call of gs itself:
>
> The blabla.ps generated by Instant preview can be in a path with spaces
> and will work as long as the gswin32c.exe isn't in a path with spaces.
>
> So it seems that gs is somewhere called together with its path, e.g.
>
> C:\Program Files\LyX\etc\Ghostscript\bin\gswin32c.exe -dNOPAUSE -dBATCH
> -dSAFER -sDEVICE=pnmraw -sOutputFile="C:\Program
> Files\LyX\~\blabla%d.ppm" -dGraphicsAlphaBit=XXX -dTextAlphaBits=XXX
> rYYY "C:\Program Files\LyX\~\blabla.ps"

That is indeed a problem. We can't quote the first word.

I think that the thing to do here is to split the full path to the executable 
into "basename" and "dirname" parts, to add the "dirname" to the PATH 
environment variable (if it's not there already) and to execute the command 
as simply
    gswin32c.exe foo bar "C:\Program Files\LyX\~\blabla.ps"

The attached patch seems to do the trick. Please test!

Regards,
Angus
Index: lib/scripts/lyxpreview2ppm.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/scripts/Attic/lyxpreview2ppm.py,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 lyxpreview2ppm.py
--- lib/scripts/lyxpreview2ppm.py	16 Jun 2005 13:15:11 -0000	1.1.2.7
+++ lib/scripts/lyxpreview2ppm.py	8 Dec 2005 00:00:55 -0000
@@ -84,6 +84,17 @@ def error(message):
     sys.exit(1)
 
 
+def prepend_if_not_present(list, candidate):    
+    found_it = 0
+    for elem in list:
+        if elem == candidate:
+            found_it = 1
+            break
+
+    if not found_it:
+        list[0:0] = [ candidate ]
+
+
 def find_exe(candidates, path):
     for prog in candidates:
         for directory in path:
@@ -93,7 +104,8 @@ def find_exe(candidates, path):
                 full_path = os.path.join(directory, prog)
 
             if os.access(full_path, os.X_OK):
-                return full_path
+                prepend_if_not_present(path, os.path.dirname(full_path))
+                return os.path.basename(full_path)
 
     return None
 
@@ -339,6 +351,10 @@ def main(argv):
     dvips   = find_exe_or_terminate(["dvips"], path)
     gs      = find_exe_or_terminate(["gswin32c", "gs"], path)
     pnmcrop = find_exe(["pnmcrop"], path)
+
+    # Update the PATH environment variable to include any additions
+    # to path.
+    os.environ['PATH'] = os.pathsep.join(path)
 
     # Compile the latex file.
     latex_call = '%s "%s"' % (latex, latex_file)

Reply via email to