It is currently April 27th, 2024, 6:54 am

RunCommand

Share and get help with Plugins and Addons
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: RunCommand

Post by RicardoTM »

Hey, maybe someone here can help me. I'm using RunCommand with cmd to copy and paste a folder. Everything works fine on Rainmeter, the problem is the log.txt file. I decided to use the cmd to create the file and everything works as expected except for the format.

Parameter:

Code: Select all

Parameter=IF NOT EXIST DFLT (echo N && echo %DATE% %TIME% Error:DFLT is missing.>>Log.txt) ELSE (IF NOT EXIST #ROOTCONFIGPATH#Gauges\[#Name] (((Xcopy DFLT #ROOTCONFIGPATH#Gauges\[#Name] /e /h /i /v && echo %DATE% %TIME% [#Name] Gauge successfully created.)>>Log.txt) && echo Y ) ELSE ((echo %DATE% %TIME% Error:[#Name] already exists.>>Log.txt) && echo N ))
Log.txt

Code: Select all

DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 file(s) copied
0 7 / 0 1 / 2 0 2 4   1 9 : 1 0 : 4 3 . 6 7   S S D   G a u g e   s u c c e s s f u l l y   c r e a t e d . 
 
 DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 file(s) copied
  0 7 / 0 1 / 2 0 2 4   1 9 : 1 3 : 3 7 . 4 6   G P U   G a u g e   s u c c e s s f u l l y   c r e a t e d . 
 
 DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 file(s) copied
0 7 / 0 1 / 2 0 2 4   1 9 : 1 4 : 5 3 . 5 4   M O B O   G a u g e   s u c c e s s f u l l y   c r e a t e d . 
 
 0 7 / 0 1 / 2 0 2 4   1 9 : 1 8 : 0 2 . 8 1   E r r o r : S S D   a l r e a d y   e x i s t s . 
 
 0 7 / 0 1 / 2 0 2 4   1 9 : 1 8 : 1 7 . 6 8   E r r o r : D F L T   i s   m i s s i n g . 
  
As you can tell, the echos I created are weirdly spaced. Does anyone know how to fix that?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: RunCommand

Post by SilverAzide »

RicardoTM wrote: January 8th, 2024, 1:28 am
Make sure you set RunCommand's option OutputType to UTF8 or ANSI. Looks like you are getting Unicode output mixed into your log file.
Gadgets Wiki GitHub More Gadgets...
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: RunCommand

Post by RicardoTM »

SilverAzide wrote: January 8th, 2024, 2:07 am
It is set to UTF8, the log.txt is not created by the measure but by the command itself. That option only affects the measure's string, which is only "Y" or "N" and it's not output to any file.

The parameter works like this:

There's a folder called DFLT (Default)

First the parameter analyzes if the folder exists, if it doesn't exist then it writes "Error:DFLT is missing." to log.txt and stops. (And the measure string = N)

If it indeed exists then it copies the folder (and everything inside) to paste it on another destination under another name.

Based on the [#Name] variable (User Input) it will look on the destination folder and see if it already exists.

If that folder exists then it stops and writes "Error:[#Name] already exists." to Log.txt (And the measure string = N)

If it doesn't exist then pastes the DFLT folder to a new destination under [#Name] and writes all the files and "[#Name] created successfully." to the Log.txt file. (And the measure string = Y)

So yeah, the problem seems to be that the XCopy command outputs on a format and echo on another format, so I guess what I need to find out is how to change the format in what echo command writes to the file.
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: RunCommand

Post by RicardoTM »

Well, It appears to be the Plugin. I ran some tests directly on the cmd and everything looks fine.
Even when I run the code as is on the console everything looks fine, here's the same log file with both entries, first from RunCommand plugin and second from cmd.

Code: Select all

DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 archivo(s) copiado(s)
0 7 / 0 1 / 2 0 2 4   2 3 : 5 6 : 3 9 . 8 0   G P U   G a u g e   s u c c e s s f u l l y   c r e a t e d . 
 
 DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 archivo(s) copiado(s)
08/01/2024  0:58:31.27 [#Name] Gauge successfully created.
Here's how the measure looks:

Code: Select all

[mRun]
Disabled=1
Measure=Plugin
Plugin=RunCommand
Parameter=IF NOT EXIST DFLT (echo N && echo %DATE% %TIME%: Error:DFLT is missing.>>Log.txt) ELSE (IF NOT EXIST #ROOTCONFIGPATH#Gauges\[#Name] (((Xcopy DFLT #ROOTCONFIGPATH#Gauges\[#Name] /e /h /i /v && echo %DATE% %TIME% [#Name] Gauge successfully created.)>>Log.txt) && echo Y) ELSE ((echo %DATE% %TIME% Error:[#Name] already exists.>>Log.txt) && echo N))
Timeout=5000
State=Hide
FinishAction=[!UpdateMeasure #CurrentSection#]
OutputType=UTF8
DynamicVariables=1
User avatar
nek
Posts: 105
Joined: November 3rd, 2019, 12:00 am

Re: RunCommand

Post by nek »

RicardoTM wrote: January 8th, 2024, 7:08 am ...

Code: Select all

[mRun]
Disabled=1
Measure=Plugin
Plugin=RunCommand
Parameter=IF NOT EXIST DFLT (echo N && echo %DATE% %TIME%: Error:DFLT is missing.>>Log.txt) ELSE (IF NOT EXIST #ROOTCONFIGPATH#Gauges\[#Name] (((Xcopy DFLT #ROOTCONFIGPATH#Gauges\[#Name] /e /h /i /v && echo %DATE% %TIME% [#Name] Gauge successfully created.)>>Log.txt) && echo Y) ELSE ((echo %DATE% %TIME% Error:[#Name] already exists.>>Log.txt) && echo N))
Timeout=5000
State=Hide
FinishAction=[!UpdateMeasure #CurrentSection#]
OutputType=UTF8
DynamicVariables=1
How about Program=%ComSpec% /C and OutputType=ANSI and StartInFolder=#SKINSPATH# on the [mRun] ?

@see
RunCommand Program option, #SKINSPATH#
cmd.exe Parameters (learn.microsoft.com)
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: RunCommand

Post by RicardoTM »

nek wrote: January 8th, 2024, 9:02 am How about Program=%ComSpec% /C
Woah! That did the trick! Thank you!

Code: Select all

08/01/2024  3:28:53.88: Error:RPG already exists.
08/01/2024  3:29:01.65: Error:SSD already exists.
08/01/2024  3:29:12.76: Copying files:
DFLT\Gauge.ini
DFLT\HSLiders\HSLiders.ini
DFLT\List\List.ini
DFLT\Settings\Settings.ini
DFLT\Variables\HSLiders.inc
DFLT\Variables\Settings.inc
6 archivo(s) copiado(s)
08/01/2024  3:29:12.76: ALPH Gauge successfully created.
08/01/2024  3:29:26.44: Error:DFLT is missing.
OutputType=ANSI and StartInFolder are not necessary in my case as the current skin folder is already default without it. And the string of mRun is just "Y" or "N" so the Type option is not important.Thank you nek.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: RunCommand

Post by SilverAzide »

RicardoTM wrote: January 8th, 2024, 9:22 am OutputType=ANSI and StartInFolder are not necessary in my case as the current skin folder is already default without it. And the string of mRun is just "Y" or "N" so the Type option is not important.Thank you nek.
I believe you are misunderstanding the purpose of OutputType. This is the output type of the console (command session), not the return text. You should use OutputType=ANSI to ensure commands executed in the console will output ANSI values, as Windows DOS commands will output Unicode in some cases.
Gadgets Wiki GitHub More Gadgets...
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: RunCommand

Post by RicardoTM »

SilverAzide wrote: January 8th, 2024, 3:05 pm I believe you are misunderstanding the purpose of OutputType. This is the output type of the console (command session), not the return text. You should use OutputType=ANSI to ensure commands executed in the console will output ANSI values, as Windows DOS commands will output Unicode in some cases.
Mmh, interesting. When I was testing it seemed to only affect the format on the string and the text file only if I used OutputFile. Thank you for the info.
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Create and Delete meters using PowerShell

Post by RicardoTM »

Well, I'm back lol. This time I'm experimenting on creating meters using PowerShell.
When I run this code in PowerShell it works, it writes the lines correctly, but if I do it in Rainmeter it doesn't.
Code:

Code: Select all

(Get-Content "test.ini" -Raw) + "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"
log.txt

Code: Select all

On line: 1 Character: 30
+ (Get-Content test.ini -Raw) + `r`n[Meter5] `rMeter=Shape `rMeterS ...
+                                ~
You must provide a value expression after the '+' operator.
On line: 1 Character: 31
+ (Get-Content test.ini -Raw) + `r`n[Meter5] `r`nMeter=Shape `r`nMeterS ...
+                                ~~~~~~~~~~~~~~~~~~~~
Unexpected token '`r`n[Meter5]' in the expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
The problem seems to be with "+" and "`r`n". If I take them out it works but it writes everything in the same line including `r`n. Should I use some specific syntax for this case?.

When I take the "+" out:

Code: Select all

On line: 1 Character: 29
+ ... st.ini -Raw) `r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle | Set-C ...
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Token '`r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle' in the expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
Sinces quotes " are necessary for the ` escape character to work on PowerShell, I also tried with double and triple quotes but no change.

This is the measure:

Code: Select all

[Add]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell  
Parameter=(Get-Content "test.ini" -Raw) "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"
State=Hide
OutputType=UTF8
OutputFile=log.txt
Edit.
Well, I changed the approach and this worked:

Code: Select all

Add-Content "test.ini" "`r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle"
Here's the complete code in case it is useful for someone else:

Test.ini

Code: Select all

[Rainmeter]
Update=-1
AccurateText=1

[Metadata]
Name= Test
Author= RicardoTM
Information= Create and Delete meters.
Version= 1.0
License= Creative Commons Attribution - Non - Commercial - Share Alike 3.0

[Variables]
N=4

[MeterStyle]
Shape=Rectangle 0,0,100,20
y=R

[Less]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=(Get-Content Test.ini -Raw) -replace '(?s)\[Meter[#N]\].*?;---' | ForEach-Object { $_.TrimEnd() } | Set-Content Test.ini -Encoding UTF8
State=Hide
OutputFile=log.txt
OutputType=UTF8
FinishAction=[!WriteKeyValue Variables N ([#N]-1)][!Refresh]

[Add]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell  
Parameter=Add-Content "Test.ini" "`n[Meter$([#N]+1)]`nMeter=Shape`nMeterStyle=Meterstyle`n`;---"
State=Hide
OutputType=UTF8
OutputFile=log.txt
FinishAction=[!WriteKeyValue Variables N ([#N]+1)][!Refresh]

[Button]
meter=shape
Shape=Rectangle 0,0,20,20 | Fill Color 125,0,0 | StrokeWidth 0
x=110
LeftMouseUpAction=[!CommandMeasure Less run]

[Button2]
meter=shape
Shape=Rectangle 0,0,20,20 | Fill Color 0,125,0 | StrokeWidth 0
x=130
LeftMouseUpAction=[!CommandMeasure Add run]

[Meter]
Meter=Shape
MeterStyle=MeterStyle
x=0
y=0

[Meter1]
Meter=Shape
MeterStyle=MeterStyle
;---

[Meter2]
Meter=Shape
MeterStyle=MeterStyle
;---

[Meter3]
Meter=Shape
MeterStyle=Meterstyle
;---

[Meter4]
Meter=Shape
MeterStyle=Meterstyle
;---