job.getPath() can't find the file

Post Reply
automation
Member
Posts: 40
Joined: Tue Jan 15, 2019 10:19 pm

job.getPath() can't find the file

Post 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?
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

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

Post by cstevens »

Try entering "cmd /c " before "java ..."
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

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

Post 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");
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
automation
Member
Posts: 40
Joined: Tue Jan 15, 2019 10:19 pm

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

Post 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);
Last edited by automation on Fri Dec 06, 2019 12:15 pm, edited 1 time in total.
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

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

Post 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");
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

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

Post 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.
automation
Member
Posts: 40
Joined: Tue Jan 15, 2019 10:19 pm

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

Post 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.
Post Reply