RunCommand plugin RunCommandプラグイン

Plugin=RunCommand

Executes an external command or program in Windows, allowing the skin to obtain and use any output from the program.Windowsで外部コマンドまたはプログラムを実行し、スキンがプログラムからの出力を取得して使用できるようにします。

There are several important differences between this and just executing a command with something like:これと、単に次のようなコマンドを実行することとの間には、いくつかの重要な違いがあります。

LeftMouseUpAction=["SomePath\SomeProgram.exe" "SomeParameters"]

  • The command can be run with a hidden initial state, to eliminate the cmd.exe (DOS) Command Prompt window that is created when an external command-line command or program is executed normally from Rainmeter.外部のコマンドラインコマンドまたはプログラムがRainmeterから正常に実行されたときに作成されるcmd.exe(DOS)コマンドプロンプトウィンドウを排除するために、隠し初期状態でコマンドを実行することができます。
  • Any output of the command to STDOUT (the "Standard Out" string output of a program in a cmd.exe Command Prompt window) can be captured, either directly, as the the value of the plugin measure, or piped to a text file for additional processing as needed.STDOUTへのコマンドの出力(cmd.exeコマンドプロンプトウィンドウ内のプログラムの "標準出力"文字列出力)は、直接、プラグインメジャーの値としてキャプチャすることも、テキストファイルにパイプ処理することもできます。必要に応じて追加処理
  • The plugin can detect that a command is "finished", and your skin can in effect wait for the command to be done before taking some action and using any returned value.プラグインは、コマンドが「終了」したことを検出することができ、実際には何らかのアクションを取って戻り値を使用する前に、コマンドが実行されるのをスキンが待つことができます。
  • The plugin can detect that a command caused a set of "error" return codes, and the skin can take some action based on success or failure of the command and the type of error.プラグインは、コマンドが一連の「エラー」戻りコードを引き起こしたことを検出でき、スキンはコマンドの成功または失敗とエラーのタイプに基づいて何らかのアクションを取ることができます。
  • The plugin can be set with a "timeout" value, which will automatically end the external command or program when the timeout value is reached.プラグインはタイムアウト値に設定することができ、タイムアウト値に達すると自動的に外部コマンドまたはプログラムを終了します。

Overview概要

What the plugin does when triggered with [!CommandMeasure MeasureName "Run"] is to execute what is defined in the measure's Program option, appending any program parameters defined in the Parameter option.プラグインがトリガーされたとき[!CommandMeasure MeasureName "Run"]に実行されるのは、メジャーのProgramオプションで定義されているものを実行し、Parameterオプションで定義されているプログラムパラメータを追加することです。

In most cases, the purpose of the plugin is to execute a Command Line Interface (CLI) program that takes some action or returns some value. Command-line programs by their nature always run in a cmd.exe Command Prompt window.ほとんどの場合、このプラグインの目的は、何らかのアクションを実行するか何らかの値を返すコマンドラインインタフェース(CLI)プログラムを実行することです。コマンドラインプログラムは、その性質上、常にcmd.exeコマンドプロンプトウィンドウで実行されます。

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.プラグインはProgramオプションで定義されたプログラムを監視し、終了時、実行可能ファイルの終了時、プログラムがSTDOUT(Standard Out)に出力した文字列をキャプチャし、プラグインメジャーの文字列値として設定します。

The string value of the measureメジャーの文字列値

The string value of the measure will be any output that the program writes to STDOUT. In effect, what you would see if you manually ran the command in a cmd.exe Command Prompt window will become the string value of the measure.メジャーの文字列値は、プログラムがSTDOUTに書き込む任意の出力になります。実際には、cmd.exeのコマンドプロンプトウィンドウで手動でコマンドを実行した場合に表示されるものが、数値データの文字列値になります。

The number value of the measureメジャーの数値

The number value of the measure will indicate if the command finished with or without any errors. You can get the number value of the measure by using Section Variables (e.g. [MeasureName:]). Before the command has first run, the number value of the measure will be -1. While the command is running, the number value of the measure will be 0. If an error occurs, the number value of the measure will indicate the type of error that has occurred. If the program finishes without error, the number value of the measure will be 1, meaning "success". These can be used to take different skin actions depending on the numeric return value.測定値の数値は、コマンドがエラー付きで終了したかどうかを示します。あなたはセクション変数(例えば[MeasureName:])を使って小節の数値を得ることができます。コマンドが最初に実行される前は、小節の数値は-1になります。コマンドの実行中は、小節の数値は0になります。エラーが発生した場合、小節の数値は発生したエラーの種類を示します。プログラムがエラーなしで終了した場合、小節の数値は1になり、「成功」を意味します。これらは、数値の戻り値に応じてさまざまなスキンアクションを実行するために使用できます。

Optionsオプション

General measure options一般的な測定オプション

All general measure options are valid.一般的な測定オプションはすべて有効です。

Program Default: %ComSpec% \U \CProgram デフォルト: %ComSpec% \U \C

The program to run. If not specified, the default value is the %ComSpec% environment variable (normally cmd.exe) with the parameters "\U" for Unicode pipe output and "\C" to close the Command Prompt window and exit the cmd.exe shell when finished.実行するプログラム 指定しない場合、デフォルト値は、Unicodeパイプ出力用のパラメータ "\ U"と、コマンドプロンプトウィンドウを閉じてcmd.exeシェルを終了するための "\ C"を指定した%ComSpec%環境変数(通常はcmd.exe)です。終了しました。

Generally it is best to leave this undefined and use the Parameter option to define the command and parameters to be executed. Command-line program will simply cause Windows to first execute cmd.exe anyway, to create the Command Prompt environment the program must run in. Basic "DOS" commands like "dir" or "copy" don't have any .exe "program" to run in any case, and are simply internal functions of cmd.exe.一般に、これを未定義のままにして、Parameter実行するコマンドとパラメータを定義するためのオプションを使用するのが最善です。コマンドラインプログラムを実行すると、Windowsが最初にcmd.exeを実行し、コマンドプロンプト環境を作成する必要があります。"dir"や "copy"などの基本的な "DOS"コマンドには、.exeプログラムはありません。 「いずれにしても実行することができ、単にcmd.exeの内部機能です。

Information on cmd.exe.情報cmd.exeを

Parameter Default: NoneParameter デフォルト: None

Command-line parameters. If no Program is specified, this option represents the entire command-line, which will be executed in the context of the default cmd.exe Command Prompt window as described above.コマンドラインパラメータ no Programが指定された場合、このオプションはコマンドライン全体を表します。これは、前述のようにデフォルトのcmd.exeコマンドプロンプトウィンドウのコンテキストで実行されます。

Note: Care should be taken to properly "quote" commands with a path or parameters having spaces in values.注:値にスペースを含むパスまたはパラメーターを使用してコマンドを正しく「引用」するように注意する必要があります。

Example: Parameter=wmic os get lastbootuptime.例: Parameter=wmic os get lastbootuptime

State Default: HideState デフォルト: Hide

Initial "visible state" of the program.プログラムの初期の「可視状態」

  • Hide (default)
    Attempts to hide the program's window from being visible. This option is not recommended for GUI programs and/or programs that expect any form of input.非表示(デフォルト)
    プログラムのウィンドウを非表示にすることを試みます。このオプションは、GUIプログラムや、いかなる形式の入力も想定しているプログラムにはお勧めできません。
  • Show
    Shows the program's normal window.表示
    プログラムの通常のウィンドウを表示します。
  • Minimized
    Attempts to start the program minimized.最小
    化プログラムを最小化して起動しようとします。
  • Maximized
    Attempts to start the program maximized.最大化最大化さ
    れたプログラムを開始しようとします。

Notes: If State=Hide, the plugin will automatically "kill" any program it executed, when either the skin is refreshed or unloaded, or Rainmeter is exited.注意:もしState=Hide、スキンが更新されたりアンロードされたり、あるいはRainmeterが終了した時、プラグインはそれが実行したプログラムを自動的に "kill"します。

A few programs with a windowed GUI user-interface (for instance Calc.exe) explicitly show themselves and will not respond to initial state requests like Hidden or Minimized. This will be a rare problem, as normally there is no useful reason to use this plugin to execute GUI programs from the command line. They will likely take no desirable independent action, and will have no STDOUT "output" in any case.ウィンドウが表示されたGUIユーザーインターフェイスを持ついくつかのプログラム(たとえばCalc.exe)は、自分自身を明示的に表示し、HiddenやMinimizedなどの初期状態の要求には応答しません。通常、このプラグインを使用してコマンドラインからGUIプログラムを実行するのに有用な理由はないため、これは稀な問題になります。彼らはおそらく望ましい独立した行動をとらず、いかなる場合でもSTDOUTの "出力"を持ちません。

FinishAction Default: NoneFinishAction デフォルト: None

Bangs or other actions that are executed when the program has finished / exited.プログラムが終了または終了したときに実行される前髪またはその他のアクション

OutputFile Default: NoneOutputFile デフォルト: None

Optional path and file name where the STDOUT output will be saved. The file's encoding is controlled by the OutputType option. The default path will be the skin folder.STDOUT出力が保存される場所のオプションのパスとファイル名。ファイルのエンコーディングはOutputTypeオプションによって制御されます。デフォルトのパスはスキンフォルダです。

OutputType Default: UTF16OutputType デフォルト: UTF16

Type of output to be expected from the program. Any OutputFile will also be encoded with these values. You must be sure that what you tell it here matches what is actually output by the program you run. This option does not "control" what is output by the program.プログラムから予想される出力のタイプ。いずれOutputFileもこれらの値でエンコードされます。あなたがここでそれを話すものがあなたが走らせるプログラムによって実際に出力されるものと一致することを確かめなければなりません。このオプションは、プログラムによって出力される内容を「制御」するものではありません。

  • UTF16 (default)UTF16(デフォルト)
  • UTF8
  • ANSI

Note: Although by default cmd.exe will be executed with the \U (UTF-16 Unicode) parameter, that does not mean that any program executed in the Command Prompt window will necessarily produce output in UTF-16. While most internal Windows commands like "dir" will produce UTF-16 output, a great many command-line programs will produce ANSI output. If you get gibberish characters returned by the measure, setting OutputType=ANSI will often correct the issue.注:デフォルトではcmd.exeは\ U(UTF-16 Unicode)パラメーターを使用して実行されますが、それは必ずしもコマンドプロンプトウィンドウで実行されたプログラムがUTF-16で出力を生成することを意味するわけではありません。"dir"のようなWindowsのほとんどの内部コマンドはUTF-16出力を生成しますが、非常に多くのコマンドラインプログラムがANSI出力を生成します。あなたがメジャーによって返されたちょっとぎこちない文字を受け取った場合、設定OutputType=ANSIはしばしば問題を修正します。

StartInFolder Default: Skin folderStartInFolder デフォルト: Skin folder

Optional path which will be used as the "Start in" folder for the executed program. The default path will be the skin folder.実行されたプログラムの「スタート」フォルダとして使用されるオプションのパス。デフォルトのパスはスキンフォルダです。

Timeout Default: -1Timeout デフォルト: -1

Timeout value in milliseconds. If positive, RunCommand will either "Close" the program if the State is other than Hide or "Kill" the program if the State is Hide. The default is -1, which means no timeout. Any FinishAction will run even if the program does not actually terminate (e.g. if closing "Notepad" and clicking "Cancel" when asked to save the document). It should be noted that this value is independent of any Update or UpdateDivider values in the skin.ミリ秒単位のタイムアウト値。正の場合は、runCommand関数は、「閉じる」プログラムがあればするかState以外のHide場合は、プログラムを「殺す」StateですHide。デフォルトは-1です。これはタイムアウトがないことを意味します。FinishActionプログラムが実際には終了しなくても(たとえば、「メモ帳」を閉じて文書の保存を求められたときに「キャンセル」をクリックした場合など)、すべて実行されます。この値はいずれかの独立していることに注意すべきUpdateか、UpdateDividerスキン内の値。

Note: Because Rainmeter strips any quotes from the start and end of an option if both exist, it is important to double double-quote the Program and Parameter options If the overall command or parameter requires both starting and ending quotes.注: Rainmeterはオプションの開始と終了の両方から引用符を削除するので、全体のコマンドまたはパラメータに開始引用符と終了引用符の両方が必要な場合は、ProgramおよびParameterオプションを二重引用符で囲むことが重要です。

Example: Program=""C:\Program Files\Some Program\Something with a space.exe""例: Program = "" C:¥Program Files¥Some Program¥Something with space.exe ""

Plugin Commandsプラグインコマンド

Run

Runs the program. The plugin will take no action unless triggered with this command.プログラムを実行します。このコマンドで起動しない限り、プラグインは何もしません。

Example: LeftMouseUpAction=[!CommandMeasure MeasureName "Run"]例: LeftMouseUpAction=[!CommandMeasure MeasureName "Run"]

Close

Sends a normal "close" message to the program.通常の「閉じる」メッセージをプログラムに送ります。

The program may produce an "are you sure?" prompt before closing. Some programs can cancel the closing of the program, in which case the plugin will continue to gather any output.プログラムは、「よろしいですか?」というメッセージを表示することがあります。閉じる前にプロンプ??トを出します。プログラムによってはプログラムのクローズをキャンセルすることができます。その場合、プラグインは出力を収集し続けます。

Example: LeftMouseUpAction=[!CommandMeasure MeasureName "Close"]例: LeftMouseUpAction=[!CommandMeasure MeasureName "Close"]

Kill

Terminates the program without notice. This should generally be used when ending a program that was run with State=Hide.予告なくプログラムを終了します。これは通常、で実行されたプログラムを終了するときに使用されるべきState=Hideです。

Example: LeftMouseUpAction=[!CommandMeasure MeasureName "Kill"]例: LeftMouseUpAction=[!CommandMeasure MeasureName "Kill"]

Error codesエラーコード

Here is a list of possible error codes returned by the plugin:

  • 100 Unknown command. This happens when an invalid !CommandMeasure command was sent to the plugin.100不明なコマンドです。これは、無効な!CommandMeasureコマンドがプラグインに送信されたときに発生します。
  • 101 Program still running. This happens when trying to Run the program again before it has finished running.101プログラムはまだ実行中です。これは、プログラムが実行を終了する前にもう一度実行しようとしたときに発生します。
  • 102 Program not running. This happens when trying to Close or Kill a program that is not running.102プログラムが実行されていません。これは、実行されていないプログラムを閉じるまたは強制終了するときに発生します。
  • 103 Cannot start program. This happens when the Program option is invalid. Usually a wrong path or typo in the Program option is the cause. Note that cmd.exe may start perfectly well but be unable to execute a command or program passed as a Parameter option. That will not trigger this error code.103プログラムを起動できません。これは、Programオプションが無効な場合に発生します。通常、プログラムオプションの誤ったパスやタイプミスが原因です。cmd.exeは完全に起動しますが、Parameterオプションとして渡されたコマンドやプログラムを実行することはできません。それはこのエラーコードを引き起こさないでしょう。
  • 104 Cannot save file. This happens when there is an error saving the file. This could happen if writing to a locked location or file. The string value of the plugin will still contain any output of the program.104ファイルを保存できません。これは、ファイルの保存中にエラーが発生したときに起こります。これは、ロックされた場所またはファイルに書き込む場合に起こります。プラグインの文字列値にはプログラムの出力が含まれています。
  • 105 Cannot terminate process. There was an error when attempting to close or kill the program. This should rarely happen. If so, it might be necessary to open the Windows Task Manager and manually close the program.105プロセスを終了できません。プログラムを終了または終了しようとしたときにエラーが発生しました。これはめったに起こらないはずです。その場合は、Windowsのタスクマネージャを開いて手動でプログラムを閉じる必要があります。
  • 106 Cannot create pipe. This happens when the plugin cannot create a pipe to the program trying to run. The program will not run if this error happens. This error should rarely happen.106パイプを作成できません。これは、プラグインが実行しようとしているプログラムへのパイプを作成できない場合に発生します。このエラーが発生した場合、プログラムは実行されません。このエラーはめったに起こりません。

Note: These error codes are produced by the plugin, and have nothing to do with any error encountered by the executed program itself. Errors from the program will generally be displayed in the STDOUT output, and can be tested for and reacted to there.

Example

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

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic cpu get Name
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#CPUName.txt
RegExpSubstitute=1
Substitute="Name.*#CRLF#":"","#CRLF#":""

[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

This example will run the program wmic.exe, which is in the Windows %PATH% and thus needs no path on the command itself.この例では、Windowsの%PATH%にあるプログラムwmic.exeを実行します。したがって、コマンド自体にパスは必要ありません。

The wmic.exe program will use the parameters of "cpu get Name". The program will be run in a "hidden" cmd.exe Command Prompt window, and nothing visible will happen.wmic.exeプログラムは、 "cpu get Name"のパラメータを使用します。プログラムは「隠された」cmd.exeコマンドプロンプトウィンドウで実行され、何も表示されません。

In effect this is really executing "%windir%\system32\cmd.exe \U \C" "wmic cpu get Name".実際にこれは本当に実行されてい"%windir%\system32\cmd.exe \U \C" "wmic cpu get Name"ます。

The output of the wmic.exe program (the "name" of your CPU in this case) will be written to STDOUT in the hidden cmd.exe Command Prompt window, which will be captured by the plugin and set as the string value of the [MeasureRun] measure.wmic.exeプログラムの出力(この場合はCPUの「名前」)は、隠されたcmd.exeコマンドプロンプトウィンドウのSTDOUTに書き込まれます。これは、プラグインによってキャプチャされ、の文字列値として設定されます。 [MeasureRun]メジャー。

The Substitute option is being used to strip off some extra label information and linefeeds that are output by the program.「代替」オプションは、プログラムによって出力される余分なラベル情報と改行を取り除くために使用されています。

Additionally, the file defined in OutputFile will contain the entire output of the wmic command, which in this example might be:さらに、OutputFileで定義されたファイルには、wmicコマンドの出力全体が含まれます。この例では、次のようになります。

Name
Intel Core i7 920 @ 3.20GHz

Additional parsing of this file could be done with the WebParser plugin or String measures if you wanted for instance to obtain multiple separate values from the single command output.たとえば、単一のコマンド出力から複数の別々の値を取得したい場合は、このファイルの追加解析をWebParserプラグインまたはStringメジャーで実行できます。

関連記事

スポンサーリンク

CREATE VIEW ビューを作成する

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る