Solved

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

Posted on 2009-07-06
6
443 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now