Page 1 of 1

job.getPath() can't find the file

Posted: Thu Dec 05, 2019 4:42 pm
by automation
I'am trying to run jar-file and it's working find if I'am not using variables like this

Code: Select all

var status = Process.execute("java -jar C:/pdfboxer.jar -trimBox 55.94803135054997,56.82283454999998,1164.1039372989,765.3543309 -sourceFile C:/myfile.pdf -destFile C:/trimmed.pdf");
If I run the code below in SwitchScipter

Code: Select all

var status = Process.execute("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + sourceFile + " -destFile C:/trimmed.pdf");
or this code with getPath

Code: Select all

var status = Process.execute("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + job.getPath() + " -destFile C:/trimmed.pdf");
I get the java error that it can't open the file.

If log sourceFile I get the correct path and I can see the pdf file in the folder.

How do I use the incoming file as the soruce file?

Re: job.getPath() can't find the file

Posted: Thu Dec 05, 2019 11:20 pm
by cstevens
Try entering "cmd /c " before "java ..."

Re: job.getPath() can't find the file

Posted: Fri Dec 06, 2019 9:35 am
by jan_suhr
Try this instead

Code: Select all

var myJob = job.getPath();
And then

Code: Select all

var status = Process.execute("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + myJob + " -destFile C:/trimmed.pdf");

Re: job.getPath() can't find the file

Posted: Fri Dec 06, 2019 12:10 pm
by automation
jan_suhr wrote: Fri Dec 06, 2019 9:35 am Try this instead

Code: Select all

var myJob = job.getPath();
And then

Code: Select all

var status = Process.execute("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + myJob + " -destFile C:/trimmed.pdf");
You have just added a variable?

That is what I did with my second code snippet that is not working.

Code: Select all

var sourceFile = job.getPath();

var status = Process.execute("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + sourceFile + " -destFile C:/trimmed.pdf");
But I get the correct path in the log with this

Code: Select all

s.log(2, sourceFile);

Re: job.getPath() can't find the file

Posted: Fri Dec 06, 2019 12:14 pm
by jan_suhr
Ok, wasn't obvious in your post.

Try this then.

(status)

Code: Select all

Process.execute(status)
Where Status is

Code: Select all

var status = ("java -jar " + scriptPath + " -trimBox "  + startX + "," + startY + "," + xmlWidth + "," + xmlHeight +  " -sourceFile " + myJob + " -destFile C:/trimmed.pdf");

Re: job.getPath() can't find the file

Posted: Tue Dec 10, 2019 2:36 pm
by freddyp
job.getPath() will most likely contain spaces so you have to quote the value when using it on the command line:

Code: Select all

var myJob = "\"" + job.getPath() + "\"";
The same goes for any other file path on the command line.

Re: job.getPath() can't find the file

Posted: Fri Dec 13, 2019 3:05 pm
by automation
freddyp wrote: Tue Dec 10, 2019 2:36 pm job.getPath() will most likely contain spaces so you have to quote the value when using it on the command line:

Code: Select all

var myJob = "\"" + job.getPath() + "\"";
The same goes for any other file path on the command line.
WOW thanks it worked! So simple but hard to find.