Greg
Greg

Reputation: 1710

Run linux command from in spring boot war file

The first question I'm asking myself is. Is it even possible to run Linux commands in a spring boot war file?

If you use this in putty it works:

/usr/local/bin/wkhtmltopdf http://www.yahoo.com /tmp/yahoo.pdf

This is what I'm trying to do in my application: This does not create a pdf and I don't now what the output is if I run this because it is on a sever as war file.

I know this works on Windows when testing on localhost.

@RequestMapping(value = "/testlinux", method = RequestMethod.POST)
public void testlinux() throws IOException {

    try {

        ProcessBuilder pb = new ProcessBuilder("/usr/local/bin/wkhtmltopdf http://www.yahoo.com /tmp/yahoo.pdf");

        pb.start();

    } catch (Exception e) {
        System.out.println(e);
    }

Any idea's or thoughts about this?

Upvotes: 0

Views: 1425

Answers (1)

Little Santi
Little Santi

Reputation: 8793

The first thing I see is that you must split command and arguments into separate strings:

ProcessBuilder pb = new ProcessBuilder("/usr/local/bin/wkhtmltopdf", "http://www.yahoo.com", "/tmp/yahoo.pdf");

Upvotes: 1

Related Questions