Solved

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

Posted on 2009-07-06
6
447 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

863 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

28 Experts available now in Live!

Get 1:1 Help Now