Dear all
I've a Powershell script that runs in an infinite loop. I am trying to start it when Rainmeter starts or refreshes. but it does not seem to run at all. If I run the script manually in a Powershell terminal, all works as it should. (I would find this easier to debug, were it Linux and Bash . .)
Here are the most relevant parts of the code.
Code: Select all
path_script_dir="C:\Scripts\rainmeter\"
Code: Select all
OnRefreshAction=[!CommandMeasure measure_command_camStatus "Kill"] [!CommandMeasure measure_command_camStatus "Run"]
Code: Select all
[measure_command_camStatus]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=-NoProfile -NoExit #path_script_dir#checkCam.ps1
State=Hide
- replacing `#path_script_dir#` with a literal string;
- removing the 'kill' line (which is there to stop multiple instances of the script from running) from OnRefreshAction;
- removing the 'NoHide' option from the RunCommand;
- removing, from the RunCommand, the 'NoProfile' or 'NoExit' options.
Also, I suppose I should give the Powershell script. So, here it is. (And I use it, er, in conjunction with a Lua script . .).
Code: Select all
$LogEngineLifeCycleEvent=$false;
$LogEngineHealthEvent=$false;
$LogProviderLifeCycleEvent=$false;
$LogProviderHealthEvent=$false;
# ----
# VARS
# ----
$path_drive="R:\"
$path_sub1="Rainmeter\"
$path_sub2="powershell\"
$path_leaf="checkCam.txt"
$path_outputFile="$path_drive$path_sub1$path_sub2$path_leaf"
# echo path_outputFile is $path_outputFile
# ----
# MAIN
# ----
#Import-Module Microsoft.PowerShell.Management
if ( ! ( Test-Path -Path $path_drive -PathType Container ) ) {
echo "ERROR: drive $path_drive does not exist."
exit 1
}
while($true) {
# PATHS
if ( ! ( Test-Path -Path "$path_drive$path_sub1" -PathType Container ) ) {
New-Item -Path "$path_drive$path_sub1" -ItemType Directory | Out-Null
if ( ! ($?) ) {
echo "ERROR: failed to create $path_drive$path_sub1."
exit 1
}
}
if ( ! ( Test-Path -Path "$path_drive$path_sub1$path_sub2" -PathType Container ) ) {
New-Item -Path "$path_drive$path_sub1$path_sub2" -ItemType Directory | Out-Null
if ( ! ($?) ) {
echo "ERROR: failed to create $path_drive$path_sub1$path_sub2."
exit 1
}
}
# GENERATE OUTPUT
(get-pnpdevice).Where{ $_.Caption -eq 'USB2.0 PC Camera' }.Status | Out-File -FilePath $path_outputFile -Encoding ASCII
# SLEEP
Start-Sleep -s 10
}
I would appreciate some help! Thanks.
EDITED.