Sublime Forum

Unable to find target command: exec

#1

Hello,

I am trying to make a build system so that Sublime text will compile my latex files for me.

I know there is a plugin for this called “Latextools”, but I prefer not to use that (because it does things that I do not want).

I use windows 8 and Miktex for latex. What I want sublime text to do (and nothing more) is to run pdflatex $file whenever I press ctrl-b, $file being the current file of course.

This is what I did. I wrote the following file

{
    "cmd": "pdflatex", "$file_name"],
//    "file_regex": "^ ]*File \"(...*?)\", line ([0-9]*)",
    "working_dir": "$file.path",
    "selector": "text.tex.latex"
}

and put it in “…/App Data/Roaming/Sublime Text 3/Packages/User/latex.sublime-build”

Now whenever I press “Ctrl-b” I get the error “Unable to find target command: exec”. What am I doing wrong? Maybe nothing, and this is some bug?

0 Likes

#2

Alright I did a little more researching. Also the build system does not work for other file types. For example I tried a simple program in *.cc, and I get the same error message.

Thus, I figured there is some problem with my ST3 installation. Therefore I removed ST3 via windows uninstall, and I also removed the files from my system that were not deleted by the installer.

Then I re-installed. I got my build file to run, and i could use Ctrl-b once (maybe twice), and then the problem reappeared: Ctrl-b gives “Unable to execute command: exec”.

I think that the python script exec.py starts running but does not close. Then when I try to start it a second time for a second build, it is already in use and windows does not allow to start it a second time. But this is just my guess. I don’t know how to program, so I don’t know how these things work.

0 Likes

#3

bump

0 Likes

#4

What is the location of pdflatex.exe ?? Try specifying the complete path to pdflatex.exe in latex.sublime-build.

"cmd": "C:\\Program Files\\PDFLatex\\pdflatex.exe", "$file_name"],

Otherwise if still does not work, you can have your build system run python code and invoke your command using subprocess.Popen. To do so, do the following:

For latex.sublime-build:

{
    "selector": "text.tex.latex",
    "target": "pdflatexbuild"
}

Create a sublime plugin file named pdflatex.py:

import sublime, sublime_plugin
import subprocess

class pdflatexbuild(sublime_plugin.WindowCommand):
	def run(self):
		filepath = self.window.active_view().file_name()
		cmd = "C:\\Program Files\\PDFLatex\\pdflatex.exe", filepath]
		sublime.active_window().run_command("show_panel", {"panel": "console"})
		try:
			process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
			processoutput = process.communicate()[0].rstrip()
			print(processoutput)
			sublime.status_message(processoutput)
		except Exception as e:
			print(str(e))

**The only line you will need to change is the one that says (replace it with your correct path to the exe):
**cmd = “C:\Program Files\PDFLatex\pdflatex.exe”, filepath]

0 Likes