Running an EXE *with arguments*

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

IanC
Posts: 8
Joined: Mon Nov 30, 2020 10:04 pm

Running an EXE *with arguments*

Post by IanC »

I'm new to PS scripting, and really pleased with what I achieved over the weekend! Stitching a lot of map tiles together using parts of the filename to determine their position.

But I am stuck on trying to run an EXE with arguments, from within a JSX. I can do it OK without arguments.

Something such as this, although the argument will vary, which works fine at the command line:
"C:\Program Files\MAPC2MAPC64\mapc2mapc64.exe" "C:\Users\Ian\Desktop\9 SP test tiles\stitched\SP.tfw"

I have searched and tried various examples in File.Execute tutorial. I'm using Windows 10.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Running an EXE *with arguments*

Post by Kukurykus »

Code: Select all

system('start "" "C:\Program Files\MAPC2MAPC64\mapc2mapc64.exe" "C:\Users\Ian\Desktop\9 SP test tiles\stitched\SP.tfw"')
IanC
Posts: 8
Joined: Mon Nov 30, 2020 10:04 pm

Re: Running an EXE *with arguments*

Post by IanC »

Perfect (nearly!), I had to use double backslashes (to Escape the backslash I think?).

Using a variable for the argument, I ended up with:

Code: Select all

var arg = ' "C:\\Users\\Ian\\Desktop\\9 SP test tiles\\stitched\\SP.tfw"'
system('start "" "C:\\Program Files\\MAPC2MAPC64\\mapc2mapc64.exe"'+arg)
Many thanks!
IanC
Posts: 8
Joined: Mon Nov 30, 2020 10:04 pm

Re: Running an EXE *with arguments*

Post by IanC »

Really weird, that was working, now doesn't seem to be....

****EDIT: Now it is (silly typo).
Last edited by IanC on Mon Nov 30, 2020 11:16 pm, edited 4 times in total.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Running an EXE *with arguments*

Post by Kukurykus »

Yes, you are right, I did not test it, but wrote from memory - double backslashes are necessary ;)
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Running an EXE *with arguments*

Post by Kukurykus »

Did you correct that typo in your posted code, what that was?
IanC
Posts: 8
Joined: Mon Nov 30, 2020 10:04 pm

Re: Running an EXE *with arguments*

Post by IanC »

Nothing important, it was only one of the folder names in the argument :D Thanks again for your help.