RunProgram, Weird Behavior

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
andyz
Newbie
Posts: 5
Joined: Wed Oct 19, 2016 7:43 pm

RunProgram, Weird Behavior

Post by andyz » Thu Feb 02, 2017 10:22 pm

There is a specific program that I am attempting to launch and automate. When the program opens I need to press a button and then set two different combo boxes to a specific value (they are already pre-populated with choices).

When I launch this program via RunProgram, for some strange reason, the combo boxes are empty with no choices. This also occurs if I use RunProgram to launch CMD.exe and pass the program as a parameter. I also set MS to launch with admin but that did not help either.

It works fine if I launch the program myself through windows explorer or via the command prompt.

What I would like to know is how macro scheduler is executing the launch of external programs. Or maybe someone can shed some light on what may be happening?

If anyone is interested in trying this it is free software (used for programming circuit boards): http://www.freescale.com/files/soft_dev ... LASHER.zip.

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

Re: RunProgram, Weird Behavior

Post by JRL » Fri Feb 03, 2017 1:39 pm

Sounds like the script can't find its home directory. Try setting the system variable "CWD" (Current Working Directory) to the path where the exe resides prior to the RunProgram line.

For example if the exe is named Lasher and is located in C:\Programs\FreeScale

Try something like

Code: Select all

Let>CWD=C:\Programs\FreeScale
RunProgram>C:\Programs\FreeScale\Lasher.exe

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: RunProgram, Weird Behavior

Post by Marcus Tettmar » Fri Feb 03, 2017 1:53 pm

To set the current working directory you need to do:

ChangeDirectory>C:\Programs\FreeScale

Setting CWD won't change the working directory. CWD only *reflects* the current working directory.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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

Re: RunProgram, Weird Behavior

Post by JRL » Fri Feb 03, 2017 2:05 pm

Thanks for the correction. Hopefully the working directory is the problem so using ChangeDirectory> will resolve the issue.

andyz
Newbie
Posts: 5
Joined: Wed Oct 19, 2016 7:43 pm

Re: RunProgram, Weird Behavior

Post by andyz » Fri Feb 03, 2017 2:44 pm

Thank you for the quick support guys. That was it - works perfect now.

To get a better understanding of this I have a few more questions:
  • Is it advisable to set the working directory every time before launching a program, or only when issues like this are observed?
  • Is the default current directory equivalent to SCRIPT_DIR?
  • Is it advisable to set the current directory back to original state after launching the program?
Thanks again!

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: RunProgram, Weird Behavior

Post by Marcus Tettmar » Sat Feb 04, 2017 7:48 am

Is it advisable to set the working directory every time before launching a program, or only when issues like this are observed?
Depends on the application in question. My experience is it is rare that you have to do this but there are some apps which need you to do it. And it's worth noting that Windows shortcuts have a "Start In" directory entry which is usually set to the folder containing the .exe. Some apps want this. Others don't care.
Is the default current directory equivalent to SCRIPT_DIR?
No, the working directory changes all the time depending on what an app/Windows is doing. When you first start Macro Scheduler it is most likely going to happen to be the main Macro Scheduler data folder, but depends on how you have things set up and what happens. So yeh most likely it is probably SCRIPT_DIR to start with but not necessarily.
Is it advisable to set the current directory back to original state after launching the program?
No, no need.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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