Running external command (VBS & WSH) & Capturing the output // Menjalanakan command Line (VBS & WSH) & menangkap output layar ke var OR file

vbscript commandLine output to var or file

Running external command (VBS & WSH) & Capturing the output // Menjalanakan command Line (VBS & WSH) & menangkap output layar ke var OR file

VB Script

There are various ways to execute an external command from VBS. Here are a few examples.
1. Using Exec

If you want to run an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams:

Example 1: Capturing the exit code:

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("notepad")

Do While oExec.Status = 0
WScript.Sleep 100
Loop

WScript.Echo oExec.Status

Example 2: Capturing the output:


Wscript.Echo runCMD("dir C:\")
Function runCMD(strRunCmd)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strRunCmd)

strOut = ""

Do While Not objExec.StdOut.AtEndOfStream
strOut = strOut & objExec.StdOut.ReadLine()
Loop

Set objShell = Nothing
Set objExec = Nothing

runCMD = strOut
End Function
2.Using Run

If you want to run a program in a new process:


object .Run(strCommand, [intWindowStyle], [bWaitOnReturn])

intWindowStyle is an integer value indicating window style. Here's a table of styles:

*** Ada berbagai cara untuk mengeksekusi perintah eksternal dari VBS. Berikut adalah beberapa contoh.
1. Menggunakan Exec

Jika Anda ingin menjalankan sebuah aplikasi pada anak-perintah shell, menyediakan akses ke stdin / stdout / stderr aliran:

Contoh 1: Menangkap kode keluar:

Dim WshShell, oExec
Set WshShell = CreateObject ("WScript.Shell")

Set oExec = WshShell.Exec ("notepad")

Apakah Sementara oExec.Status = 0
WScript.Sleep 100
Lingkaran

WScript.Echo oExec.Status

Contoh 2: Menangkap output:


Wscript.echo runCMD ("dir C: \")
Fungsi runCMD (strRunCmd)
Set objShell = WScript.CreateObject ("WScript.Shell")
Set objExec = objShell.Exec (strRunCmd)

Strout = ""

Apakah Sementara Tidak objExec.StdOut.AtEndOfStream
Strout = Strout & objExec.StdOut.ReadLine ()
Lingkaran

Set objShell = Tidak ada
Set objExec = Tidak ada

runCMD = Strout
End Function
2.Using Run

Jika Anda ingin menjalankan sebuah program dalam suatu proses baru:


objek Run. (strCommand, [intWindowStyle], [bWaitOnReturn])

intWindowStyle adalah nilai integer yang menunjukkan gaya jendela. Berikut adalah tabel gaya:

Back to posts
Comments:

Post a comment


XtGem Forum catalog