Page 1 of 1

Running WIN batch files containing %1 and %2 variables

Posted: Sun Mar 05, 2017 9:47 am
by jan_suhr
I have a case where I need to run an Windows command prompt application and it has to be done as a batch-file ( .bat ) and I need to get the Switch variables %1 and %2 in to that batch files as the file paths for it to process.

I have done it on Mac with shell scripts but can't get it to work in the batch file on Windows.

Thanks


Jan

Re: Running WIN batch files containing %1 and %2 variables

Posted: Sun Mar 05, 2017 2:09 pm
by jan_suhr
A lot ot trial and error finally got it right.

This is different depending on what app you run in Execute Command. In the case of PDF Toolkit it will not accept the spaces in the path if you just write the command in the Arguments property. Other CLI apps accept this but not PDFtk.

And in some cases the file variables need quotes and in some no quotes.

So in the arguments I have this "%1" "%2"

And in Command or path I have the path to the Batch file that will shuffle the 2 pages in a PDF so that the last page is first page.

Code: Select all

C:\switch_scripts\shuffle.bat
Batch file looks like this

Code: Select all

set inputfile=%1
set outfile=%2
pdftk.exe A=%inputfile% cat A2 A1 output %outfile%

Hope this will help someone.

Jan

Re: Running WIN batch files containing %1 and %2 variables

Posted: Mon Apr 08, 2019 5:21 pm
by r.zegwaard
Thanks Jan, it saved my day! :lol:

Re: Running WIN batch files containing %1 and %2 variables

Posted: Mon Apr 08, 2019 8:32 pm
by jan_suhr
r.zegwaard wrote: Mon Apr 08, 2019 5:21 pm Thanks Jan, it saved my day! :lol:
You're welcome. Since this was a while ago I have now made an app that solves this problem in a much easier way.

https://www.enfocus.com/en/appstore/pro ... and-friend