howto pass argument / parameter to script?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
dragonetti
Posts: 13
Joined: 20 Jan 2013 15:27

howto pass argument / parameter to script?

Post by dragonetti »

I searched for this but I really could not an suitable solution.
The closest:
http://www.xyplorer.com/xyfc/viewtopic. ... er#p118078

question 1
If I have a catalog item which has the following line in the "Location" field:

Code: Select all

load "f:\scripts\test.xys";
Can I hardcode a parameter / argument in the above line and message it out, if "test.xys" contains:
If it is possible, what do I need add at the question mark below in the code?

Code: Select all

$a= ?   // what do I need to enter here to access the argument/parameter....
 msg $a;


question 2
Let's say I am in windows command line and if I use the method described in the help file (chapter: "Command Line Switches"):

Code: Select all

f:\xyplorer\XYplorer.exe /script="f:\scripts\test.xys" /user="a|b|c"
Then "test.xys" outputs the correct passed argument.

But when after XYplorer is loaded I execute the same command again, but in stead of "/user="a|b|c" , I use "/user="1|2|3".
XYplorer outputs, the previous (original) "a|b|c". I can understand that this is as it was meant to work.
But is it possible to have it output the updated (changed) argument/parameter: "1|2|3"

highend
Posts: 14949
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: howto pass argument / parameter to script?

Post by highend »

One way:

Catalog - Location field:

Code: Select all

::perm $p = "/test"; load "test.xys";
While your script (test.xys) contains:

Code: Select all

perm $p;

    text $p;
    unset $p;
Configuration > Refresh, Icons, History > Scripting > Remember permanent variables must be checked in the config for this to work.

The same works for a script, that you invoke via a dos box.

Code: Select all

f:\xyplorer\XYplorer.exe /script="::perm $p = '/def'; load 'test.xys';"
One of my scripts helped you out? Please donate via Paypal

dragonetti
Posts: 13
Joined: 20 Jan 2013 15:27

Re: howto pass argument / parameter to script?

Post by dragonetti »

Thank you very much for this!

highend
Posts: 14949
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: howto pass argument / parameter to script?

Post by highend »

Regarding parsing command line arguments you can also have a look at the script command get():

Code: Select all

 "CmdLine", [token]
Returns the app's command line, or a specific token of it. Examples:
echo get("CmdLine");    //returns the command line (without application)
echo get("CmdLine", 0); //returns the application as called
echo get("CmdLine", 1); //returns the 1st argument
echo get("CmdLine", 2); //returns the 2nd argument, etc. 

- "CmdLineUser", [token]
Returns the user field of the command line (passed via command line switch /user), or a specific token of it. 
One of my scripts helped you out? Please donate via Paypal

dragonetti
Posts: 13
Joined: 20 Jan 2013 15:27

Re: howto pass argument / parameter to script?

Post by dragonetti »

How coincidental I was just looking at that exact section in the "Get" command in the help file under Scripting Command Reference!
Then I saw your post!
Thank you!

Post Reply