Solved

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

Posted on 2009-07-06
6
453 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:dy211
  • 4
  • 2
6 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24785537
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

0
 

Author Comment

by:dy211
ID: 24785957
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??
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24785989
Try preceeding your strCmd with cmd /c or cmd /k.  You will need to specify the full path:

strCmd = "cmd /c c:\My Projects\jsonchecker\bin\Release\jsonchk < "& strLine

(probably even more appropriate to get the %comspec% variable - either via "%comspec% /c ..." or objShell.ExpandEnvironmentStrings("%comspec%")
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 67

Expert Comment

by:sirbounty
ID: 24785997
Hmm - try removing the ,4, True as well - I'm not certain those are valid for Exec...
0
 

Author Closing Comment

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

worked.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24786845
Glad I could help - thanx for the grade! :^)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question