Passing parameters through cli to second-level script


I am facing an issue with parameter passing between scripts.

My main requirement is to send the value for a “TypeText” command dynamically. The structure of my script is as below:

  • Script 1 has a function that references some other functions in another script. hence in script 1, I am passing the command line value as:

params TypeString
callFunction TypeString

to callFunction TypeString
callAnotherScriptFunction TypeString
end to

Now in the second script I have declared the following:

params TypeString
callAnotherScriptFunction TypeString
TypeText TypeString

I think I am making some mistake somewhere, always the value against the TypeText is “TypeString” instead of the value that is sent from the CLI.

Note that the on the CLI, I am sending the parameters using -params 2000.

Is there a simpler method to this.

Thanks in advance.

Your code fundamentally looks okay, and should work. I suggest you try working through it a little piece at a time to see where it’s failing. Instead of calling your main script from the command line, try calling it from another script. That way you can run it within Eggplant and step through line-by-line in the debugger, using the Do box to “put” the values of your variables as you go.

If that seems okay, then from the command line try running a very simple script that logs the parameter value that it receives using a “Log” command. Work with very simple scripts that don’t do anything other than passing parameters and logging them and you should be able to get this to work. If not, let us know and we’ll be happy to help you more.

ok. Thanks.

I have a small clarification. I tried to find for the results in ref docs, but could not find though.


Say, I have a main script that references functions from various other scripts. Now, all the other scripts need parameters to be passed from the CLI.

So, my doubt here is, is it possible to send different command line parameters to different scripts and how should the scripts identify that (say) first argument is for functoin in script 1 and 2nd arg is for function in script 2 and so on…

Thanks a ton for your detailed explanations. Appreciate it a lot. :slight_smile:

Parameter passing from the command line is limited to a single set of parameters which are passed to the last script called. This isn’t really too serious of a limitation though, since scripts can call other scripts. So the trick is to have the command line run an Eggplant script that takes all of the incoming parameters and does the right thing with them.

You’ll have to decide exactly how you want to do this based on your particular needs, but here’s one possible approach:

From the command line, instead of calling several scripts independently, call a central “Dispatcher” script, passing the names of other scripts to call, along with their parameters:

/Applications/ ~/Documents/Dispatcher.suite/Scripts/Dispatcher.script -params Script1 "1,2,3" Script2 "Jimmy,Joe,Jack"

The command above is all on one line. There are 4 parameters following ‘-params’ – ‘Script1’ is the name of the first script to call, followed by its parameters, then ‘Script2’ followed by its parameters. In each case the parameters are passed as a single string, with commas separating the individual values. We’ll use that to split them up in the Dispatcher script. Here it is:

-- Dispatcher.script
repeat with n=1 to the paramCount - 1 stepping by 2
	put param(n) into scriptName
	put param(n+1) into scriptParams
	do scriptName && scriptParams
end repeat

The dispatcher simply steps through each pair of parameters that was passed in, and uses the “do” command (which executes a string as though it were part of the script at that point) to call each script along with its parameters. I hope this is clear, and shows at least one way to accomplish what you’ve asked.

Yes. This does solve the issue to a large extent. THANKS!!

I have one last clarification:

To put a value into a variable we use the “PUT” command. Say, I need to send the output of a function into another function as the parameter. how can this be done.

To be clear

// firstFunction (string) -- This works
put firstFunction (string) into message -- This doesn't work for strings 
secondFunction (message)

to firstFunction  string1
	Log " Format Test" & "   " & string1
end to

to secondFunction string2 
	Log  string2
end to

Is there a way to pass the string output function itself as a parameter to the second function.

The problem is that your firstFunction doesn’t return anything, so its default return value is empty (which is what is then put into message). Try adding the command “return string1” (or whatever you want to return) at the end of the firstFunction handler.

You can also pass the return value of one function directly to another function if you like:

put secondFunction(firstFunction(string))

(although this command won’t show anything either, unless you change secondFunction to return something!)