It is currently April 25th, 2024, 8:43 am
RunCommand
-
- Posts: 1740
- Joined: November 13th, 2012, 9:53 pm
Re: RunCommand 1.0
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.
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Getting WinRAR exit codes with the RunCommand plugin
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.
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?
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
So, is it possible to check the WinRAR exit code with the RunComand plugin?
-
- Developer
- Posts: 2681
- Joined: November 24th, 2011, 1:42 am
- Location: Utah
Re: RunCommand 1.0
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:
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
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
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
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: RunCommand 1.0
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].
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].
-
- Posts: 2
- Joined: December 14th, 2013, 9:04 pm
- Location: Colorado, USA
Re: RunCommand 1.0
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!
So thanks a ton!
"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
-
- Posts: 56
- Joined: February 5th, 2014, 3:44 pm
- Location: Canada
Re: RunCommand 1.0
Could you share your code? I'm looking at basically doing the same type thing with some WMI calls. ;o)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!
Thanks in Advance!
Edit: Good example provided by jsmorley here: http://rainmeter.net/forum/viewtopic.php?p=97951#p97951
-
- Posts: 1740
- Joined: November 13th, 2012, 9:53 pm
Re: RunCommand 1.0
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:
and test.vbs looks like:
the result on the console is:
just something simple as:
Code: Select all
[Command]
Measure=Plugin
Plugin=RunCommand
Program=""cscript.exe""
Parameter=""#@#test.vbs""
Output=Utf16
Code: Select all
wscript.echo "Hello World"
-
- Posts: 56
- Joined: February 5th, 2014, 3:44 pm
- Location: Canada
Re: RunCommand 1.0
I've seen this before with Powershell.
http://social.technet.microsoft.com/Forums/windowsserver/en-US/8d5716d9-1387-4e32-82a1-baa50018d4fb/output-files-contain-strange-chinese-characters?forum=winserverpowershell
Have you tried:
Output=ANSI
and/or
Output=ASCII
http://social.technet.microsoft.com/Forums/windowsserver/en-US/8d5716d9-1387-4e32-82a1-baa50018d4fb/output-files-contain-strange-chinese-characters?forum=winserverpowershell
Have you tried:
Output=ANSI
and/or
Output=ASCII
-
- Posts: 1740
- Joined: November 13th, 2012, 9:53 pm
Re: RunCommand 1.0
no, i didn't. made-up code usually doesn't work.Grim wrote:I've seen this before with Powershell.
http://social.technet.microsoft.com/Forums/windowsserver/en-US/8d5716d9-1387-4e32-82a1-baa50018d4fb/output-files-contain-strange-chinese-characters?forum=winserverpowershell
Have you tried:
Output=ANSI
and/or
Output=ASCII
the correct key is OutputType, Ascii is not a valid option.
and yeah,first post wrote:OutputType - Type of output to be expected. Options include: Ansi, Utf8, or Utf16 (default).
moshi wrote:no matter which encoding i set, i'll always get Chinese.
-
- Developer
- Posts: 2681
- Joined: November 24th, 2011, 1:42 am
- Location: Utah
Re: RunCommand 1.0
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.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:and test.vbs looks like:Code: Select all
[Command] Measure=Plugin Plugin=RunCommand Program=""cscript.exe"" Parameter=""#@#test.vbs"" Output=Utf16
the result on the console is:Code: Select all
wscript.echo "Hello World"
Something like this:
Code: Select all
[Command]
Measure=Plugin
Plugin=RunCommand
Parameter=""cscript.exe" "#@#test.vbs""
Output=Utf16
Unfortunately I am out of town for a couple of weeks and cannot really test or debug this problem at this time.
-Brian