|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBS WSH -> getting a string from a dos excutable
Is there a way to pass what a dos executable into a varible in a vbs?
Here is the code: Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") ' open normal and don't wait WSHShell.Run "CheckCorruptImage.exe ./ *.jpg no >>log.txt", 1, false Set WSHShell = Nothing WScript.Quit(0) How would I get the string to this? tempVar = WSHShell.Run "CheckCorruptImage.exe ./ *.jpg no >>log.txt", 1, false the executable return a problem with the path of the image if its is corrupt. |
|
#2
|
|||
|
|||
|
Clumsy, but you could always use the filesystem object to open and read the log file.
I've seen VB6 code that uses some windows api to capture the output of a dos program, but I don't know how or if you can do that with wscript.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
||||
|
||||
|
But of course you can! WSH would be much good without this capability now would it?
Do some Googling for the WSH's WshScriptExec object. If you need a little more help, just post back and I'll be glad to go into more detail. Hint: WSH has two native methods for executing command lines (or batch file ).object.Run() object.Exec() Run will only return an error code. Exec, however, allows you to work with the output generated by a command. These are the two pieces of info you need. You'll use the Exec() method to run your batch file and the WshScriptExec object to retrieve its output. Alternatively, you could run all of your batch commands in native WSH. You can use the StdOut object to work with output and avoiding having to run an external program. |
|
#4
|
||||
|
||||
|
I decided to just go ahead and construct the code. One thing you may need to test. I seem to remember the Exec method requiring full paths, so you may need to add the location to your executable. Anyway, here's your basic code construct.
Code:
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("CheckCorruptImage.exe ./ *.jpg no >> log.txt")
Set objStdOut = objWshScriptExec.StdOut
strOutput = objStdOut.ReadAll
WScript.Echo strOutput
|
|
#5
|
|||
|
|||
|
Quote:
Thanks I will give that a try |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBS WSH -> getting a string from a dos excutable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|