Running WIN batch files containing %1 and %2 variables

Post Reply
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Running WIN batch files containing %1 and %2 variables

Post 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
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

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

Post 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
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

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

Post by r.zegwaard »

Thanks Jan, it saved my day! :lol:
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

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

Post 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
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Post Reply