It is currently April 25th, 2024, 6:15 am

Powershell won't exit with RunCommand Plugin.

Get help with creating, editing & fixing problems with skins
chao-samu
Posts: 6
Joined: June 23rd, 2017, 10:13 am

Powershell won't exit with RunCommand Plugin.

Post by chao-samu »

When I'm using the RunCommand Plugin with powershell, I have to kill the powershell.exe because it won't exit after finishing the command.

Killing by hand and then looking in the written STDOUT, redirected with OutputFile, shows that the command was run sucessfully.

I'm not really seeing the problem. Maybe someone can help.

For testing I'm using the standard example from the rainmeter docs of RunCommand, with an adapted "MeasureRun".

Code: Select all

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

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "echo '123'"
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#stdout.txt

[MeterRun]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click to Run
LeftMouseUpAction=[!CommandMeasure MeasureRun "Run"]

[MeterResult]
Meter=String
MeasureName=MeasureRun
Y=10R
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Powershell won't exit with RunCommand Plugin.

Post by eclectic-tech »

Instead of starting PowerShell by using Command=PowerShell.exe, just add "PowerShell" to the Parameter line:

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=PowerShell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "echo '123'"
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#stdout.txt
EDIT: Corrected missing carriage return in edited code :oops: ... if this doesn't correct the issue, perhaps one of the PS Guru's here can help. :welcome:
User avatar
khanhas
Posts: 40
Joined: October 26th, 2016, 5:00 pm

Re: Powershell won't exit with RunCommand Plugin.

Post by khanhas »

If you're looking for a more native way to call powershell command or run a whole script, you can try PowershellRM: https://github.com/khanhas/PowershellRM

Go to release page to download .rmskin package and install plugin.

Basically, PowershellRM plugin is like a Lua script measure but using Powershell instead, it has nearly same option (ScriptFile), behaviour (get value from Update function) and provides some more like:
- Powershell has deep integration with Windows both in high and low level so you can do so much more with it than Lua.
- Ability to define short script right in INI file instead of creating an additional script file.
- Parent/Children measure relationship to get multiple result without invoking script again.

Here is a skin snippet based on your RunCommand plugin measure rewritten in PowershellRM plugin

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=PowershellRM
ExecutionPolicy = Bypass
Line = echo '123' | Set-Content stdout.txt
UpdateDivider = -1
Taking advantage pipeline feature of Powershell, you can echo (alias of `Write-Output`) and export to file with just one single line.

Working directory, on default, is your skin folder so you don't need to write full file path.

Although ExecutionPolicy is not really needed here, you probably have to change it when importing not-your-code script.
chao-samu
Posts: 6
Joined: June 23rd, 2017, 10:13 am

Re: Powershell won't exit with RunCommand Plugin.

Post by chao-samu »

@eclectic-tech thx but that's also not working for me, but I found here the solution in another thread which I will write down shortly :)

@khanhas thx for recommending this self written plugin from you. Nice work btw. I will look into it if I need some more powershell, but for now it would be to much.

--

Solution:
It's a powershell bug that still persist in Windows 7 because it's shipped with an old version (2) of it.

It's well described here: https://forum.rainmeter.net/viewtopic.php?t=16715&start=80#p103088

In short it has to be:

Code: Select all

Program="powershell.exe"
Parameter="-inputformat none -NoProfile -NonInteractive -command "echo '123'"