Link to home
Start Free TrialLog in
Avatar of dy211
dy211

asked on

After running a program using .run in VBS, how do I store the outputs?

Below is the code I have so far to run jsonchk.exe, however jsonchk executes in a cmd window and disappears almost instantly before I can see any output.

jsonchk.exe is ran by jsonchk < param, so strLine is provided.

So my question is, how can I store the output produced by jsonchk.exe into a .txt file and for each function call in the for loop, APPEND the new output to that .txt file?

Thanks!
for each strIn in arrFileLines
             processLine(strIn)
	next
 
function processLine(strLine)
	dim objShell
	set objShell = wscript.CreateObject("WScript.Shell")
	objShell.Run "./jsonchecker/bin/Release/jsonchk.exe < "&strLine, 4, True
	set objShell = Nothing
end function

Open in new window

Avatar of sirbounty
sirbounty
Flag of United States of America image

You'll need to use .Exec instead of .Run and redirect the output...

Example (may require some manipulating based on what you're looking to achieve):
for each strIn in arrFileLines
             processLine(strIn)
        next
 
function processLine(strLine)
        dim objShell : set objShell = wscript.CreateObject("WScript.Shell")
        dim objExec : Set objExec = objShell.Exec "./jsonchecker/bin/Release/jsonchk.exe < "&strLine, 4, True
        strOutput = objExec.StdOut.ReadAll
        wscript.echo strOutput
        set objShell = Nothing
end function

Open in new window

Avatar of dy211
dy211

ASKER

sirbounty, thanks for the quick response. Exec definitely seems to be the better option. However, in order to run jsonchk, it must be jsonchk.exe < something or jsonchk < something

so when I set strCmd to strCmd = ".\jsonchecker\bin\Release\jsonchk < "&strLine
and when I .Exec(strCmd) I get the error from StdErr.ReadAll: "Illegal characters in path"

however, just typing .\jsonchecker\bin\Release\jsonchk < something.json in cmd.exe works.

anyone know how to fix this problem??
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm - try removing the ,4, True as well - I'm not certain those are valid for Exec...
Avatar of dy211

ASKER

TY sirbounty,
strCmd = "cmd /c C:\""Documents and Settings""\person1\Desktop\scripts\jsonchecker\bin\Release\jsonchk.exe < "&strLine

worked.
Glad I could help - thanx for the grade! :^)