0

I have a script in python that should receive two PDF files and output an image. It works fine in the terminal but when I try to run it in a Java process using process builder it gives me a syntax error and I am not sure why.

I am using python3 with the command (in the terminal):

python3 /pathToMyPythonScript/command_line.py /Users/myname/Desktop/one.pdf /Users/myname/Desktop/two.pdf > /Users/myname/Desktop/XXXXXXXXXXXXXXXXXXXXX.png

It works and produces the desired output.

also tried:

/usr/local/bin/python3 /pathtomypythonscript/command_line.py /Users/myname/Desktop/one.pdf /Users/myname/Desktop/two.pdf > /Users/myname/Desktop/XXXXXXXXXXXXXXXXXXXXX.png

and it also works fine.

When I call the same script in my java code using the following code:

Process p = new ProcessBuilder("/usr/local/bin/python3", fileOneLocation, fileTwoLocation, outputFileDestination).inheritIO().start();

all variables are declared and all files exist.

My eclipse console output is an error:

File "/Users/myname/Desktop/one.pdf", line 1
    %PDF-1.3
    ^
SyntaxError: invalid syntax

What am I missing here? It works fine in terminal but not in Java.

4
  • In your Java code, shouldn't there be the python file to run? Currently there only is a call to python and then passing the pdfs - but not your actual Python script Commented Mar 16, 2018 at 11:50
  • @hage From what I read Java process works with a command and not a script. You're probably thinking of a solution using Jython or so. Commented Mar 16, 2018 at 11:53
  • Nevermind @hage you were right. I feel so bad for not noticing something like this. Thank you. Forgot to add the scriptPathVariable in the Process Builder. Commented Mar 16, 2018 at 11:56
  • No. In your commandline example, you call python command_line.py one.pdf two.pdf But in your Java code there is no reference to your python script and the interpreter thinks that its first argument is the script - but it actually is a pdf file Commented Mar 16, 2018 at 11:56

1 Answer 1

1

As an answer:

You forgot to mention your actual python script in the ProcessBuilder

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.