Java exec executeDotCommand(final File dotFile)

Here you can find the source of executeDotCommand(final File dotFile)

Description

Execute Graphviz dot's command to generate the pdf file.

License

Open Source License

Parameter

Parameter Description
dotFile a parameter

Exception

Parameter Description
IOException an exception
InterruptedException an exception

Declaration

private static File executeDotCommand(final File dotFile) throws IOException, InterruptedException 

Method Source Code


//package com.java2s;
/*//from w  w w.  j av a2s . c  o m
 * Copyright 2012 jccastrejon
 *  
 * This file is part of ExSchema.
 *
 * ExSchema is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * ExSchema is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
    
 * You should have received a copy of the GNU General Public License
 * along with ExSchema. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Execute Graphviz dot's command to generate the pdf file.
     * 
     * @param dotFile
     * @throws IOException
     * @throws InterruptedException
     */
    private static File executeDotCommand(final File dotFile) throws IOException, InterruptedException {
        Process process;
        int processCode;
        File returnValue;
        String dotCommand;

        returnValue = new File(dotFile.getParent(), "schemas.pdf");
        dotCommand = "dot -Tpdf " + dotFile.getAbsolutePath() + " -o " + returnValue.getAbsolutePath();
        process = Runtime.getRuntime().exec(dotCommand);
        processCode = process.waitFor();
        dotFile.delete();

        if (processCode != 0) {
            throw new RuntimeException("An error ocurred while executing: " + dotCommand);
        }

        return returnValue;
    }
}

Related

  1. executeCommandForceDir(String baseCommand, String osPath, File file)
  2. executeCommandLine(String command)
  3. executeCommandLineReturnAll( final String[] command)
  4. executeCommandLinux(final String _command)
  5. executeDELETE(String parameters)
  6. executeGET(DataInputStream sockInp, DataOutputStream sockOutp)
  7. executeGetStatus(ProcessBuilder pb)
  8. executeIt(String command)
  9. executeLocalCommand(String[] command)