It is currently September 23rd, 2020, 3:42 pm

RunCommand

Share and get help with Plugins and Addons
User avatar
moshi
Posts: 1850
Joined: November 13th, 2012, 9:53 pm

Re: RunCommand 1.0

Post by moshi »

thanks for the reply. i already had an alternative method using "brute-force" substitutions, but thanks for the Lua example, might be handy for a different project.
User avatar
Mordasius
Posts: 1077
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Getting WinRAR exit codes with the RunCommand plugin

Post by Mordasius »

I have a skin that uses the RunCommand plugin with WinRAR to zip a folder and then send the ZippedFile as an email attachment using sendEmail.

Code: Select all

[mZipFiles]
Measure=Plugin
Plugin=RunCommand
Program=""C:\Program Files\WinRAR\rar.exe""
parameter=" a -as -df -k -tb[mToday] #ZippedFile# #SourceFolder# "
;;;                -df ^ delete files from SourceFolder
;;;                     -k locks the .rar file 
FinishAction=[!PauseMeasure #CURRENTSECTION#]  [!EnableMeasure mSendReport] [!CommandMeasure mSendReport Run]
DynamicVariables=1
Disabled=1

[mSendReport]
Measure=Plugin
Plugin=RunCommand
Program=""#@#sendEmail.exe""
Parameter=" -f #MailFrom# -t #MailTo# -u #MailSubject# -m #MailBody# -a #ZippedFile# -s smtp.gmail.com:587 -xu #UserName# -xp #UserPassword# -o tls=yes "
FinishAction=[!PauseMeasure #CURRENTSECTION#] 
DynamicVariables=1
Disabled=1
Everything works just fine. However, I'd like to be able to modify the FinishAction of [mZipFiles] based on the WinRAR exit code. In this case, I don't want to enable or run the mSendReport measure if the WinRAR exit code is >0 meaning something didn't work out so there is no point in sending the file.

So, is it possible to check the WinRAR exit code with the RunComand plugin?
User avatar
Brian
Developer
Posts: 2062
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: RunCommand 1.0

Post by Brian »

If the WinRAR program prints the numerical code when finished, this plugin should be capturing it and setting it as the "string" value of the measure.

From there you should have a few options. You might try the new IfMatch/IfConditions or you could enable some Lua script that will perform different action based on the string value of the WinRar measure.

For example:
IfMatch:

Code: Select all

[mZipFiles]
Measure=Plugin
Plugin=RunCommand
Program=""C:\Program Files\WinRAR\rar.exe""
parameter=" a -as -df -k -tb[mToday] #ZippedFile# #SourceFolder# "
;;;                -df ^ delete files from SourceFolder
;;;                     -k locks the .rar file

; 0 = Success, 1 = Warning, ... etc.
IfMatch=0
IfMatchAction=[!EnableMeasure mSendReport][!CommandMeasure mSendReport Run]
IfMatch2=1
IfMatchAction2=[!Log "Warning!"]

DynamicVariables=1
Disabled=1

[mSendReport]
Measure=Plugin
Plugin=RunCommand
Program=""#@#sendEmail.exe""
Parameter=" -f #MailFrom# -t #MailTo# -u #MailSubject# -m #MailBody# -a #ZippedFile# -s smtp.gmail.com:587 -xu #UserName# -xp #UserPassword# -o tls=yes "
DynamicVariables=1
Disabled=1
Something like that might work. You may need to match it like this: IfMatch=^0$.

BTW - I don't think there is any reason to ever "Pause" a RunCommand measure as it will only run once and "Pausing" will never affect the program you are running.

Again, this is all dependent on if the WinRar program actually prints out the exit code to the screen. If so, RunCommand should capture it and return it as the string value of the measure. If not, then I don't think there is anything that can be done.

-Brian
User avatar
Mordasius
Posts: 1077
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RunCommand 1.0

Post by Mordasius »

Unfortunately, WinRAR doesn't print the numerical exit code when it finishes. However, that's not a problem now that I know about the IfMatchActions. Thanks for the Heads-Up Brian, I guess I was still hungover or asleep when they were announced at the beginning of the year!

WinRAR ends with a "Done" when it successfully generates an archive so a combination of IfMatch=.*Done$ and IfNotMatchAction= is all that's needed to handle errors.

P.S. I can't remember what I was trying to achieve with FinishAction=[!PauseMeasure #CURRENTSECTION#]. Also, I don't suppose there is much point in disabling/enabling RunCommand measures as they don't do anything until hit with [!CommandMeasure MeasureName Run].
User avatar
Infinimbal
Posts: 2
Joined: December 14th, 2013, 9:04 pm
Location: Colorado, USA

Re: RunCommand 1.0

Post by Infinimbal »

Just want to thank you for an exceptional plugin. I've been looking for a reliable way to get a hold of a MAC address for a skin I'm making and none of the other solutions I've tried have worked out for me. I managed to use RunCommand to capture the results of an ipconfig /all command and then parse for the MAC using a regex.

So thanks a ton!
"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
User avatar
Grim
Posts: 58
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: RunCommand 1.0

Post by Grim »

Infinimbal wrote:Just want to thank you for an exceptional plugin. I've been looking for a reliable way to get a hold of a MAC address for a skin I'm making and none of the other solutions I've tried have worked out for me. I managed to use RunCommand to capture the results of an ipconfig /all command and then parse for the MAC using a regex.

So thanks a ton!
Could you share your code? I'm looking at basically doing the same type thing with some WMI calls. ;o)

Thanks in Advance!

Edit: Good example provided by jsmorley here: http://rainmeter.net/forum/viewtopic.php?p=97951#p97951
User avatar
moshi
Posts: 1850
Joined: November 13th, 2012, 9:53 pm

Re: RunCommand 1.0

Post by moshi »

i noticed that i have troubles with VBS files' output. no matter which encoding i set, i'll always get Chinese.

just something simple as:

Code: Select all

[Command]
Measure=Plugin
Plugin=RunCommand
Program=""cscript.exe""
Parameter=""#@#test.vbs""
Output=Utf16
and test.vbs looks like:

Code: Select all

wscript.echo "Hello World"
the result on the console is:

Code: Select all

Microsoft (R) Windows Script Host, Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. Alle Rechte vorbehalten.

Hello World
User avatar
Grim
Posts: 58
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: RunCommand 1.0

Post by Grim »

User avatar
moshi
Posts: 1850
Joined: November 13th, 2012, 9:53 pm

Re: RunCommand 1.0

Post by moshi »

no, i didn't. made-up code usually doesn't work. ;)

the correct key is OutputType, Ascii is not a valid option.
first post wrote:OutputType - Type of output to be expected. Options include: Ansi, Utf8, or Utf16 (default).
and yeah,
moshi wrote:no matter which encoding i set, i'll always get Chinese.
User avatar
Brian
Developer
Posts: 2062
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: RunCommand 1.0

Post by Brian »

moshi wrote:i noticed that i have troubles with VBS files' output. no matter which encoding i set, i'll always get Chinese.

just something simple as:

Code: Select all

[Command]
Measure=Plugin
Plugin=RunCommand
Program=""cscript.exe""
Parameter=""#@#test.vbs""
Output=Utf16
and test.vbs looks like:

Code: Select all

wscript.echo "Hello World"
the result on the console is:

Code: Select all

Microsoft (R) Windows Script Host, Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. Alle Rechte vorbehalten.

Hello World
You might try to run the command directly through cmd.exe with the \U option. You can do this by removing your Program option and use the default one, then add "cscript.exe" to your Parameter option.
Something like this:

Code: Select all

[Command]
Measure=Plugin
Plugin=RunCommand 
Parameter=""cscript.exe" "#@#test.vbs""
Output=Utf16
If that doesn't work, you can manually change the code page inside a batch file using the "mode" command. Something like this: mode con cp select=[Your code page]. You may need to change it back to the original code page after you have run the VBS code.

Unfortunately I am out of town for a couple of weeks and cannot really test or debug this problem at this time.

-Brian