How do I pass an array element as a parameter to an external command?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DaveF
Posts: 24
Joined: 14 Nov 2016, 17:01

How do I pass an array element as a parameter to an external command?

24 May 2024, 14:32

Hi

How do I pass an array element as a parameter to an external command?

Code: Select all

Result[1] := "DSC01688.jpg"
Result[2] := "DSC01680.jpg"
XX := Result[1]	
YY := Result[2]	
		
run %comspec% /k ffmpeg -i "%XX%" -i "%YY%" -update true -filter_complex hstack output2.jpg
The above works as expected, but how do I place the array elements directly in the run command.
Like this, but works:

Code: Select all

run %comspec% /k ffmpeg -i "%Result[1]%" -i "%Result[2]%" -update true -filter_complex hstack output2.jpg

I'm guessing I'm baffled by the syntax
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: How do I pass an array element as a parameter to an external command?

24 May 2024, 14:54

try:

Code: Select all

run, % comspec " /k ffmpeg -i " Result[1] " -i " Result[2] " -update true -filter_complex hstack output2.jpg"
14.3 & 1.3.7
DaveF
Posts: 24
Joined: 14 Nov 2016, 17:01

Re: How do I pass an array element as a parameter to an external command?

24 May 2024, 16:44

Thanks for the prompt reply,
This is all beyond me as I was unaware 'comspec' environmental variable could be run within AHK
It leads onto to the next question of how to run it without 'comspec'?
AHK 1.1.34.03, Win 10 Pro. Latest Firefox
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: How do I pass an array element as a parameter to an external command?

24 May 2024, 17:40

I am not sure you can. But you can hide the "dos window". Try:

Code: Select all

run, % comspec " /c ffmpeg -i " Result[1] " -i " Result[2] " -update true -filter_complex hstack output2.jpg",,Hide
14.3 & 1.3.7
DaveF
Posts: 24
Joined: 14 Nov 2016, 17:01

Re: How do I pass an array element as a parameter to an external command?

25 May 2024, 11:39

Thanks again.

Another problem that's reared its head is strings with spaces get split

Code: Select all

Result[1] := "DSC01688.jpg"
Result[2] := "DSC01681 shops.jpg"
XX := Result[1]	
YY := Result[2]	
		
;run, % comspec " /k ffmpeg -y -i " Result[1] " -i " Result[2] " -update true -filter_complex hstack output2.jpg"
run %comspec% /k ffmpeg -y -i "%XX%" -i "%YY%" -update true -filter_complex hstack output2.jpg
The above works, but if it's run using the commented out command, it returns the error:
DSC01681: No such file or directory
AHK 1.1.34.03, Win 10 Pro. Latest Firefox
User avatar
Datapoint
Posts: 311
Joined: 18 Mar 2018, 17:06

Re: How do I pass an array element as a parameter to an external command?

25 May 2024, 12:25

DaveF wrote:The above works, but if it's run using the commented out command, it returns the error:
DSC01681: No such file or directory
The quotes from your original version may be required since Result[2] contains a space in the file name.
You can test it with MsgBox to confirm the string matches your desired result.
Use "" within an expression for literal quotes. https://www.autohotkey.com/docs/v1/misc/EscapeChar.htm

Code: Select all

MsgBox % comspec " /k ffmpeg -y -i """ Result[1] """ -i """ Result[2] """ -update true -filter_complex hstack output2.jpg"
DaveF wrote:
24 May 2024, 16:44
It leads onto to the next question of how to run it without 'comspec'?
Run CMD might work. https://www.autohotkey.com/docs/v1/Variables.htm#ComSpec
Maybe I misunderstood the question.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Hansielein, Lpanatt and 310 guests