It is currently April 19th, 2024, 1:12 pm

[NOT A BUG] Memory error running a CScript script from RunCommand

Report bugs with the Rainmeter application and suggest features.
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

[NOT A BUG] Memory error running a CScript script from RunCommand

Post by Yincognito »

...\Skin.ini:

Code: Select all

[Variables]

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

---Measures---

[Events]
Measure=Plugin
Plugin=RunCommand
Program=CScript
Parameter=\"#@#Event Log Test.vbs\"
State=Hide
OutputType=ANSI
Timeout=10000

---Meters---

[Result]
Meter=String
SolidColor=0,0,0,128
FontColor=255,255,255,255
FontSize=16
Padding=5,5,5,5
AntiAlias=1
MeasureName=Events
Text=Events:#CRLF#%1
LeftMouseUpAction=[!UpdateMeasure Events][!CommandMeasure Events "Run"]
...\@Resources\Event Log Test.vbs:

Code: Select all

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Event written to an event log using a script."
Result:
RunCommand CScript script.jpg
Question:
So, what's up with that? I'm just trying to eventually capture the STDOUT output of a script in CScript using RunCommand and display it in the skin. This particular script doesn't output anything, I only used it for simplicity in illustrating the behavior. It works fine from CMD, by the way. The \" are to escape quotes and are needed in this case. Placing everything in the Parameter option doesn't change anything, nor does renaming the script to a .wsf extension. Any thoughts?
You do not have the required permissions to view the files attached to this post.
Last edited by Yincognito on May 23rd, 2023, 8:15 pm, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Brian
Developer
Posts: 2679
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG?] Memory error running a CScript script from RunCommand

Post by Brian »

Yincognito wrote: May 12th, 2023, 7:05 pm It works fine from CMD, by the way. The \" are to escape quotes and are needed in this case. Placing everything in the Parameter option doesn't change anything, nor does renaming the script to a .wsf extension. Any thoughts?
I don't think the Windows command parser likes "escaped" quotes.

I do think this is one of those "double" quotes situations, like the manual describes.
https://docs.rainmeter.net/manual/plugins/runcommand/#Timeout (See the Note under Timeout)

Try this: Parameter=""#@#Event Log Test.vbs""

The innermost and outermost quotes will be removed by Rainmeter before sending the parameter to the system command processor.

-Brian

PS - This might be a good time to mention that VBScript can now be removed from a Windows 11 (build 25309) installation. Microsoft may remove this altogether in the future (or possibly leave it to the user to install it separately instead of by default).
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] Memory error running a CScript script from RunCommand

Post by Yincognito »

Brian wrote: May 13th, 2023, 5:02 am I don't think the Windows command parser likes "escaped" quotes.

I do think this is one of those "double" quotes situations, like the manual describes.
https://docs.rainmeter.net/manual/plugins/runcommand/#Timeout (See the Note under Timeout)

Try this: Parameter=""#@#Event Log Test.vbs""

The innermost and outermost quotes will be removed by Rainmeter before sending the parameter to the system command processor.

-Brian

PS - This might be a good time to mention that VBScript can now be removed from a Windows 11 (build 25309) installation. Microsoft may remove this altogether in the future (or possibly leave it to the user to install it separately instead of by default).
Thank you very much for the solution, it works. :thumbup:
Thanks for the P.S. as well, thankfully I might just avoid VBScript altogether, since it seems I can do the things I want to do (a real time event log monitor) from PowerShell anyway. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] Memory error running a CScript script from RunCommand

Post by Yincognito »

Brian wrote: May 13th, 2023, 5:02 amTry this: Parameter=""#@#Event Log Test.vbs""
I'm sure this is something specific to PowerShell (maybe regarding running it as a Job?), but since this also works in PS but not in RunCommand, here it is:

Code: Select all

[Events]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=-command While ($True) {Write-Host 'A Second Passed!'; Start-Sleep -Milliseconds 1000;}
State=Hide
OutputType=ANSI
This endless loop displays the messages just fine in PS, yet it doesn't when in RunCommand. I'm guessing that the "busy" / "unfinished" status in the loop prevents the messages from being sent to STDOUT where RunCommand can capture them? I'll try finding a solution to it, but if you know how can this be handled, care to share how?

P.S. The endless loop can be stopped in PowerShell via CTRL+C. In Rainmeter, refreshing the skin takes care of stopping PS and therefore the loop.
EDIT: Just noticed that the manual says that the "plugin will monitor the program defined in the Program option, and when it ends, when the executable terminates, any string output the program did to STDOUT (Standard Out) will be captured and set as the string value of the plugin measure", so I suppose there's no solution to this since PS would still be running when I expect the output to be displayed... :(
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Brian
Developer
Posts: 2679
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG?] Memory error running a CScript script from RunCommand

Post by Brian »

Yincognito wrote: May 13th, 2023, 8:14 pm EDIT: Just noticed that the manual says that the "plugin will monitor the program defined in the Program option, and when it ends, when the executable terminates, any string output the program did to STDOUT (Standard Out) will be captured and set as the string value of the plugin measure", so I suppose there's no solution to this since PS would still be running when I expect the output to be displayed... :(
Correct. Unfortunately with RunCommand, there is no way to capture output from a command at regular intervals while the program is running.

Other than having the command write to a file and having WebParser read it periodically (or on-demand with the Update command), I'm not sure of a way that Rainmeter can capture output from an on-going process.

-Brian
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG?] Memory error running a CScript script from RunCommand

Post by Yincognito »

Brian wrote: May 14th, 2023, 5:09 am Correct. Unfortunately with RunCommand, there is no way to capture output from a command at regular intervals while the program is running.

Other than having the command write to a file and having WebParser read it periodically (or on-demand with the Update command), I'm not sure of a way that Rainmeter can capture output from an on-going process.

-Brian
Yep, I was trying to do everything without writing to a drive for performance considerations (of both the process and drive life), and there are some alternatives like the eventcreate.exe (set part) / wevtutil.exe (get part) combo that is fast and can be captured by RunCommand, but they are a bit more restrictive than the other variants and don't allow something closer to near realtime monitoring (hence the plugin idea in the other thread)...

It appears there aren't variants that tick all the boxes here, or at least they're slightly difficult to find.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth