Home Download Buy Blog Forum Support

[BUG] Launching external commands with Popen

[BUG] Launching external commands with Popen

Postby Marciano on Fri Oct 21, 2011 3:55 am

Updated 10/23: put [BUG] in title, clarified a few issues about the test script.

I am having a weird issue with subprocess.Popen as invoked from my LaTeXTools plugin. A user reported the following bug: a LaTeX file containing a picture originally in eps format fails to compile when building from ST2, but builds just fine when invoking the exact same command that the plugin uses from the command line.

What's special (sort of) about this file is that the LaTeX graphics package, upon encountering the eps file, is smart enough to invoke the epstopdf command from within tex, and then import the resulting pdf file. This is what fails under ST2.

I can confirm that running the appropriate latex build command from the command line works just fine. In fact, I wrote a python script that invokes the exact same command used by the LaTeXTools plugin, using subprocess.Popen---again, this is copied line by line from the plugin. The results: if I run the script from the command line, everything works. If I run the script from within the ST2 console, I have exactly the same behavior that I observe when I build from ST2. I reproduce the script below for convenience.

What is going on? Is there some limitation on processes run from ST2 that in turn spawn other processes? Note that TeXshop has no trouble at all with eps file conversion on the fly.

Here's the script. Again, this is *not* the plugin code: just a standalone test script. The actual plugin code gets the file name from the current view, etc. Also note that the path is set so tex and friends (including epstopdf) are reachable. Also, I tested this on OS X; I haven't tried it on Windows. The problem exists up to the current release, 2134.

Code: Select all
import sys, os, os.path
import subprocess

make_cmd = ["latexmk",
      "-e", "$pdflatex = q/pdflatex %O -synctex=1 %S/",
      "-f", "-pdf"]

file_name = os.path.normpath("/Users/xxxxx/Documents/temp/sublimeTests/epstest/epstest.tex")
tex_dir = os.path.dirname(file_name)

cmd = make_cmd + [file_name]
print cmd

path = "$PATH:/usr/texbin"
old_path = os.environ["PATH"]
os.environ["PATH"] = os.path.expandvars(path).encode(sys.getfilesystemencoding())

os.chdir(tex_dir)
proc = subprocess.Popen(cmd)
proc.wait()

os.environ["PATH"] = old_path

print proc.returncode
Last edited by Marciano on Sun Oct 23, 2011 3:33 pm, edited 1 time in total.
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Launching external commands with Popen

Postby aparajita on Fri Oct 21, 2011 7:16 am

Marciano wrote:What's special (sort of) about this file is that the LaTeX graphics package, upon encountering the eps file, is smart enough to invoke the epstopdf command from within tex, and then import the resulting pdf file. This is what fails under ST2.


It may be a path issue. ST2 does not inherit the shell environment, and by default PATH is /bin:/sbin:/usr/bin:/usr/sbin.
aparajita
 
Posts: 177
Joined: Sun Jul 24, 2011 10:42 pm

Re: Launching external commands with Popen

Postby Marciano on Fri Oct 21, 2011 1:11 pm

It may be a path issue. ST2 does not inherit the shell environment, and by default PATH is /bin:/sbin:/usr/bin:/usr/sbin.


I don't think so. Notice that I set the path in the test script, which is exactly what I do in the plugin. All (la)tex executables are on /usr/texbin, including epstopdf...
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Launching external commands with Popen

Postby Marciano on Sat Oct 22, 2011 3:35 pm

Bump...? Jps?
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: [BUG] Launching external commands with Popen

Postby trinix on Tue Oct 25, 2011 1:24 pm

I can second this behavior. In my LaTeX-case it results in not compiling any eps files into pdf files.

See my post here: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=3386&start=0
OS X, MacTeX 2013, ST 2, Skim
trinix
 
Posts: 30
Joined: Tue Sep 20, 2011 1:57 pm

Re: [BUG] Launching external commands with Popen

Postby Marciano on Tue Oct 25, 2011 2:30 pm

Thanks trinix. Jon, the question is, are there any restrictions imposed on a process that is launched via subprocess.Popen from ST2? For instance, are stdin/stdout redirected? Again, subprocess.Popen works (i.e. latexmk runs just fine, invoking epstopdf) if the test Python script (which contains essentially the same relevant code as the plugin file make_pdf.py) is run from the command line (i.e. the Terminal).

Any ideas?
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: [BUG] Launching external commands with Popen

Postby trinix on Mon Oct 31, 2011 10:40 am

What about this issue? It makes me more and more unable to work on certain LaTeX-projects which need dealing with EPS files!
OS X, MacTeX 2013, ST 2, Skim
trinix
 
Posts: 30
Joined: Tue Sep 20, 2011 1:57 pm

Re: [BUG] Launching external commands with Popen

Postby Marciano on Mon Oct 31, 2011 2:47 pm

Jon, how can I help you track this bug down?
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: [BUG] Launching external commands with Popen

Postby tito on Mon Oct 31, 2011 3:30 pm

Maybe encoding each parameter with
Code: Select all
aParameter.encode(sys.getfilesystemencoding())

And on Windows you need to escape "^" character such
Code: Select all
string.replace('^', '^^')
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 855
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: [BUG] Launching external commands with Popen

Postby tito on Mon Oct 31, 2011 3:32 pm

you can also try using cwd= parameter instead of changing dir.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 855
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Next

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 19 guests