private int runDvi(String fileName, int resolution) throws IOException, InterruptedException, ServletException {
        int depth = 0;

        String[] command = String.format(DVI_COMMAND, 
                Integer.toString(RESOLUTIONS[resolution]), 
                fileName + IMAGE_SUFFIX,
                fileName + ".dvi").split(" ");
        SystemCommandHandler dvi = new SystemCommandHandler(command);
        dvi.setDirectory(dir);
        dvi.enableStdOutStore();
        dvi.executeAndWait();
        if (dvi.getStdOutIOException() != null)
            throw new ServletException("An IO error occuring when running 'dvi'.", dvi.getStdOutIOException());
        if (dvi.getStdErrIOException() != null)
            throw new ServletException("An IO error occuring when running 'dvi'.", dvi.getStdErrIOException());
        if (dvi.getExitCode() != 0)
            throw new DviException("Command 'dvi' failed during execution.");

        for (String output : dvi.getStdOutStore()) {
        	Matcher matcher = DEPTH_PATTERN.matcher(output);
        	if (matcher.matches()) {
	        	String depthStr = matcher.group(1);
                depth = Integer.parseInt(depthStr);
                break;
        	}
        }

        return depth;
    }