How to have MS access a variable returned from CLI command

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

How to have MS access a variable returned from CLI command

Post by Warren » Fri Nov 24, 2017 5:52 pm

I'm trying to move past GUI commands wherever possible, so diving into using MS for CLI, accessing API's, etc.

Launching a profile from Multiloginapp using a bat file command:

Code: Select all

Run>multiloginapp-cli.bat -create-profile -name "profile name" -browser-type chrome
This works to create a profile. So far, so good, but their documentation then says:
This function returns the ID of created profile
I've been googling phrases like "Read variable returned from CLI command", etc, but answers seem to be splintering off in different directions, and I seem to be attempting all the wrong permutations.

What's the simplest way to tell MS to read the returned value (string) and store it as a MS variable?

(Let>profileID=returnedString)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to have MS access a variable returned from CLI comma

Post by JRL » Sat Nov 25, 2017 4:59 am

Have you tried redirecting the output of the batch file to a text file then assigning the text file contents to a Macro Scheduler variable. If the variable contents are empty then the redirection didn't work. But its what I would try first.

Something like this:

Code: Select all

Let>RP_Wait=1
Let>RP_Windowmode=0
Run>multiloginapp-cli.bat -create-profile -name "profile name" -browser-type chrome > %temp_dir%CLIRes.txt

ReadFile>%temp_dir%CLIRes.txt,vData
MDL>vData

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: How to have MS access a variable returned from CLI comma

Post by Warren » Sun Nov 26, 2017 1:35 am

That worked. Thx. Halfway there.

I returns a bunch of stuff, then at the end:
Profile created successfully. Profile id is 40e7de3e-4d8d-44e6-97dd-b287a95d8784.
The period at the end is not part of the profile id. I've run a couple. Not entirely sure yet if they always have the same number of characters, but even if they are I suppose that could change, so it would seem the best way would be to look for everything after "Profile id is " and then ditch the period at the end.

Reading through all string functions now and trying to piece that function together. Not seeing how to do this with only the string handling functions listed. Is this a case for RegEx? Poring through anything I can find on RegEx online currently, but it's a ton of info, and not sure if it all works in MS or if there is a simpler way to do this.

I tried reading anything I could on here for info as well. I get the general impression it looks something like this based upon the my favorite regex post:

Code: Select all

RegEx>(?<=Profile id is ).*?(?=.)
(look for everything between "Profile id is " and "." ) But not sure how that passes to a MS var, and error says the function is looking for 6 parameters.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to have MS access a variable returned from CLI comma

Post by JRL » Sun Nov 26, 2017 4:33 am

Sure this can be done using regex but I prefer MS string functions.

Code: Select all

Let>vData=Profile created successfully. Profile id is 40e7de3e-4d8d-44e6-97dd-b287a95d8784.
Separate>vData,Profile id is ,vItem
StringReplace>vItem_2,.,,ProfileID

MDL>ProfileID

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: How to have MS access a variable returned from CLI comma

Post by Warren » Mon Nov 27, 2017 2:41 pm

Working flawlessly, thx.

I apparently underestimated some of the built in string functions when I looked at them. Reading back through each.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts