Solved

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

Posted on 2009-07-06
6
456 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

789 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