// 例 (JScript)
var shell = new ActiveXObject("WScript.Shell");
Script.Echo(shell.SpecialFolders("MyDocuments"));
' 例 (VBScript)
Dim shell
Set shell = CreateObject("WScript.Shell")
Script.Echo shell.SpecialFolders("MyDocuments")
// 例 (JScript)
function exec_command(cmd_str)
{
var shell = new ActiveXObject("WScript.Shell");
var exec = shell.Exec("%comspec% /c " + cmd_str);
while (!exec.StdOut.AtEndOfStream)
Script.Echo(exec.StdOut.ReadLine());
while (!exec.StdErr.AtEndOfStream)
Script.Echo(exec.StdErr.ReadLine());
return exec.ExitCode;
}
Script.Quit(exec_command("dir"));
' 例 (VBScript)
Function exec_command(cmd_str)
Dim shell, exec
Set shell = CreateObject("WScript.Shell")
Set exec = shell.Exec("%comspec% /c " & cmd_str)
Do While Not exec.StdOut.AtEndOfStream
Script.Echo exec.StdOut.ReadLine
Loop
Do While Not exec.StdErr.AtEndOfStream
Script.Echo exec.StdErr.ReadLine
Loop
exec_command = exec.ExitCode
End Function
Script.Quit exec_command("dir")
※上記スクリプト中の exec.StdOut は外部コマンドにとっての出力ストリームで、スクリプトからはコマンドが出力したテキストを読み出すことができます (StdErr も同様)。
Sazanami Help
Copyright (c) 2023 Narumi Watanabe.
All Rights Reserved.