Passing an Array Argument to Shell Using CFExecute
Written by Simon Bailey
Here’s a small post offering a solution to an issue I had recently. My goal was to run a shell script using cfexecute, one of the arguments being an Array itself. If your passing arguments in this manner on Linux (my flavour) elements are copied into an array of exec() arguments and I kept getting an error back from ColdFusion stating I was trying to pass off a complex object as a simple one (or something along those lines - makes sense). So the key was trying to fathom out how to pass my array of Strings to this Shell script, after a bit of trial and error I got it working by doing the following: + From Flex I now join the Array of Strings to form a space separated String e.g. myArrayOfStrings.join(’ ‘); + I then create an Array of arguments in ColdFusion to pass to the Shell script:
1 2 3 4 5 6 7 8 9 10 |
|
- And lastly in the Shell script I create an Array from the joined_strings argument, looping through this and performing necessary actions on each element:
1 2 3 4 5 6 7 8 9 |
|
Output in Flex:
1 2 3 |
|
This is not my area of expertise so if anyone can offer better solutions they would be appreciated.
This link helped with the final hurdle, thank you to the author!