It is currently April 27th, 2024, 11:37 pm

Run command at startup and return STDOUT as string

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Run command at startup and return STDOUT as string

Post by balala »

What Rainmeter version do you have?
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Run command at startup and return STDOUT as string

Post by FreeRaider »

I don't use Windows 10, so...
is cmd.exe the default Command Prompt?
if you open cmd.exe and type net statistics server or net statistics srv, do you get some result?

Another version

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnRefreshAction=[!CommandMeasure MeasureECHO "Run"]

[MeasureECHO]
Measure=Plugin
Plugin=RunCommand
Program=%COMSPEC% /U /C
Parameter=For /F "tokens=3,4" %G in ('net statistics server ^| find /I "Statistiche da"') DO ECHO %G %H
State=Hide
RegExpSubstitute=1
Substitute="(?siU)^.*ECHO.*(\d+/\d+/\d+ \d+:\d+:\d+)\s+.*$":"\1"

[MeterOne]
Meter=String
MeasureName=MeasureECHO
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
AmbientMike
Posts: 25
Joined: October 18th, 2016, 2:26 pm

Re: Run command at startup and return STDOUT as string

Post by AmbientMike »

Yes the command works perfectly when run manually.

I was initially using the portable version (which I think I really need to use as I'm looking to run this on 32 and 64-bit platforms (Windows 7, 8.1 and 10) and having installed the 64-bit version that does return the data correctly.

I have run the command in both a 32-bit and 64-bit command prompt and they both return the same data so why is Rainmeter 32-bit not returning the right info on a 64-bit platform?

Do you need to set "Program" to be C:\Windows\Sysnative\cmd.exe when running the 32-bit version on a 64-bit platform?
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Run command at startup and return STDOUT as string

Post by FreeRaider »

I have tested it with Program=C:\Windows\system32\cmd.exe /U /C ,Program=C:\Windows\SysWOW64\cmd.exe /U /C and without Program option (I am on Windows 7 64-bit, having a 32-bit portable installation) and it works in all cases.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Run command at startup and return STDOUT as string

Post by balala »

I guess in the initial, portable installation, the RunCommand plugin was missing. To be honest I'm not sure if the portable Rainmeter has the plugins, but I have this feeling. That's why I asked which is the version of Rainmeter.
AmbientMike
Posts: 25
Joined: October 18th, 2016, 2:26 pm

Re: Run command at startup and return STDOUT as string

Post by AmbientMike »

In the 32-bit logs I get...
!CommandMeasure: Not supported

But I don't get that in the 64-bit logs (which obviously works).

This is on the 3.3.2 Final Release. Are you going to tell me I need to be on a beta release?
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Run command at startup and return STDOUT as string

Post by balala »

AmbientMike wrote:In the 32-bit logs I get...
!CommandMeasure: Not supported

But I don't get that in the 64-bit logs (which obviously works).

This is on the 3.3.2 Final Release. Are you going to tell me I need to be on a beta release?
If I'm not wrong the 3.3.2 version had the RunCommand plugin, so it should work. But I'm not sure what is (was) the situation with the portable versions of Rainmeter (I never used one).
Anyway, using the latest version of Rainmeter (even if it's a beta one) is always a good idea. I never had problems with them.
AmbientMike
Posts: 25
Joined: October 18th, 2016, 2:26 pm

Re: Run command at startup and return STDOUT as string

Post by AmbientMike »

Disappointing that the 32 and 64-bit versions don't seem to be in-line with each other on a final release as we try to avoid running beta software wherever possible. Never mind though...

One last question on this then...

If I only want to run the command and return it once at load of the skin and not on refresh how would I accomplish that? Presumably using a "Bang" with this code...

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[Some bangs or commands]
UpdateDivider=-1
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Run command at startup and return STDOUT as string

Post by balala »

AmbientMike wrote:Disappointing that the 32 and 64-bit versions don't seem to be in-line with each other on a final release as we try to avoid running beta software wherever possible. Never mind though...

One last question on this then...

If I only want to run the command and return it once at load of the skin and not on refresh how would I accomplish that? Presumably using a "Bang" with this code...

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[Some bangs or commands]
UpdateDivider=-1
Using the UpdateDivider=-1 option on this measure is not a good idea.
Instead I'd remove this option and also I'd use the following IfEqualAction: IfEqualAction=[!CommandMeasure MeasureECHO "Run"][!DisableMeasure "#CURRENTSECTION#"]. The !DisableMeasure bang will disable this measure, once it reaches the value 1.
Also don't forget to remove the [!CommandMeasure MeasureECHO "Run"] bang from the OnRefreshAction option ([Rainmeter] section).