How do you execute a command-line program, and return the results into a variable 
Author Message
 How do you execute a command-line program, and return the results into a variable

Example:

I want to execute regread.exe (nt resource kit) from WshShell.Run, and have
it return the results into a variable.

Any help would be appreciated.  Thanks.



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable

The standard method of processing the output of command-line programs
is to redirect the output to a file. You can then open the file for
reading and manipulate its contents however you desire. If for some
reason the program doesn't send usable results to file, you should
still be able to get at its output by using the StdIn and StdOut
properties of WSH.


Example:

I want to execute regread.exe (nt resource kit) from WshShell.Run, and
have
it return the results into a variable.

Any help would be appreciated.  Thanks.



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable
You can't actually Shell.Run a program that outputs to StdOut and read that output using StdIn from
the same script.  You *can* run the program (behind %comspec% /c ) and pipe the output into another
script executed under cscript.  For your purposes, just use the redirection technique...

Shell.Run

--
Michael Harris
MVP Scripting


I can't seem to get the syntax right on StdIn or StdOut.  Can you give me an
example?


Quote:

> The standard method of processing the output of command-line programs
> is to redirect the output to a file. You can then open the file for
> reading and manipulate its contents however you desire. If for some
> reason the program doesn't send usable results to file, you should
> still be able to get at its output by using the StdIn and StdOut
> properties of WSH.



> Example:

> I want to execute regread.exe (nt resource kit) from WshShell.Run, and
> have
> it return the results into a variable.

> Any help would be appreciated.  Thanks.



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable
I can't seem to get the syntax right on StdIn or StdOut.  Can you give me an
example?


Quote:

> The standard method of processing the output of command-line programs
> is to redirect the output to a file. You can then open the file for
> reading and manipulate its contents however you desire. If for some
> reason the program doesn't send usable results to file, you should
> still be able to get at its output by using the StdIn and StdOut
> properties of WSH.



> Example:

> I want to execute regread.exe (nt resource kit) from WshShell.Run, and
> have
> it return the results into a variable.

> Any help would be appreciated.  Thanks.



Mon, 11 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable

I have to disagree with your observation that you can't Shell.Run a
program and read its output from StdIn in the same script. Try
drag-dropping a file or folder on the script below. It will return the
results of the DIR command via StdIn on that file or folder.

Dim Shell
Set Shell = CreateObject("Wscript.Shell")
If WScript.Arguments.Count = 1 Then
   Shell.Run "%comspec% /cdir/a-d """ & WScript.Arguments(0) &_
             """|cscript """ & Wscript.ScriptFullName & """",0
   WScript.Quit
End If
Shell.Popup Wscript.StdIn.ReadAll


: You can't actually Shell.Run a program that outputs to StdOut and
read that output using StdIn from
: the same script.  You *can* run the program (behind %comspec% /c )
and pipe the output into another
: script executed under cscript.  For your purposes, just use the
redirection technique...
:
: Shell.Run
:
: --
: Michael Harris
: MVP Scripting



Mon, 11 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable
Sure, you can do what you've illustrated, but you have 2 separate instances of the script.  One
instance does the Shell.Run and a completely separate instance reads StdIn...

--
Michael Harris
MVP Scripting


I have to disagree with your observation that you can't Shell.Run a
program and read its output from StdIn in the same script. Try
drag-dropping a file or folder on the script below. It will return the
results of the DIR command via StdIn on that file or folder.

Dim Shell
Set Shell = CreateObject("Wscript.Shell")
If WScript.Arguments.Count = 1 Then
   Shell.Run "%comspec% /cdir/a-d """ & WScript.Arguments(0) &_
             """|cscript """ & Wscript.ScriptFullName & """",0
   WScript.Quit
End If
Shell.Popup Wscript.StdIn.ReadAll


: You can't actually Shell.Run a program that outputs to StdOut and
read that output using StdIn from
: the same script.  You *can* run the program (behind %comspec% /c )
and pipe the output into another
: script executed under cscript.  For your purposes, just use the
redirection technique...
:
: Shell.Run
:
: --
: Michael Harris
: MVP Scripting



Mon, 11 Nov 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Execute command line program from VBScript

2. How do you execute a command-line program, and return the results into a variable?

3. How to execute a command line command from a *.HTA

4. return the result text from a VB ADODB.Connection.Execute command

5. use the result of the VBS for other application under the command line

6. Piping results of command line call to file from ASP

7. Piping results of command line call to file from ASP

8. How do you execute a Command line App inside a VB program

9. executing vb programs using command line parameters

10. Executing command line program from VB 5 application under Windows XP environmen

11. Execute command line program from VB

12. How do I execute command line programs from within VB

 

 
Powered by phpBB® Forum Software