Enhancement Request - Command variable

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Enhancement Request - Command variable

Post by Bob Hansen » Mon Mar 08, 2004 4:20 am

I'd like to suggest creating a new variable for the command interpreter.
Right now if you don't remember that there are multiple versions of command.com to use with Run Program, then you end up with a problem when the script is run in a different environment.

Even if you do plan ahead for multiple environments, you need to make different IF statements. It would be much easier to use a system variable in the command line.

Example:
Win 9X environment
Run Program>command.com /c find "mystring" c:\folder\myfile.txt > found.txt
Win NT environment
Run Program>cmd /c find "mystring" c:\folder\myfile.txt > found.txt
Both environments, simplified:
MidStr>OS_VER,1,2,Version
If>%Version%95,NT

Label>9x
Run Program>command.com /c find "mystring" c:\folder\myfile.txt > found.txt
Goto>More

Label>NT
Run Program>cmd /c find "mystring" c:\folder\myfile.txt > found.txt

Label>More
When doing for multiple environments, this techinque may be done multiple times, every time a Run Program uses a command line command.

With a variable for the interpreter, like OS_COMMAND, we could do something like:
Run Program>%OS_COMMAND% /c find "mystring" c:\folder\myfile.txt > found.txt
and use this in all environments.

This approach would also provide for upward growth. Example: If moving from WIN9X to XP, scripts need to be modified now. This approach would allow transport of scripts to newer OS without modifications.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Mar 08, 2004 9:34 am

Hi,

You could use the following Subroutine (just thrown together - might need a tweak) to do it for you:

GoSub>GetOsCmd
Run>%OS_COMMAND% bla bla bla

SRT>GetOsCmd
Position>95,OS_VER,1,is95
Position>98,OS_VER,1,is98
If>is95>0,Old
If>is98>0,Old
Let>OS_COMMAND=CMD.EXE
Goto>DoneCmdVer
Label>Old
Let>OS_COMMAND=COMMAND.COM
Label>DoneCmdVer
End>GetOsCmd
MJT Net Support
[email protected]

Lumumba

Post by Lumumba » Mon Mar 08, 2004 3:32 pm

Was part of a VBScript I've found ... tweak it.

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHEnvX = WSHShell.Environment("Process")
if WshEnvX("OS") = "Windows_NT" then WshShell.run("WinNT.VBS")
if not WshEnvX("OS") = "Windows_NT" then WshShell.run("Win9x.VBS")

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Mar 08, 2004 5:04 pm

Thanks to support for the subroutine. It is funny, but soon after I submitted the request, I thought of the same approach.. Not using a sub routine, but just creating the OS_COMMAND variable at the beginning of the scripts.

And I keep forgetting about VB script in Macro Scheduler. Probably because I still have much to learn in that area, but examples like this help out. Thanks Lumumba for the kick toward that area.

Still would like to see a permanent variable, but work arounds get the job done. This certainly is not critical.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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