Solved

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

Posted on 2009-07-06
6
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

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 …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

718 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