VBS script output

I've created a vbs script this is to run FCIV and pipe all output to a log file.

I can run this from the command line and it works -

fciv.exe -v -xml NCRTestFiles.xml > output.log

However, when I run via the script, no file is created.  Where did I go wrong?

Set wshShell = WScript.CreateObject( "WScript.Shell" )
Const DeleteReadOnly = True 
Set objFSO = CreateObject("Scripting.FileSystemObject") 


dim strDate
dim logName
dim strCommand

'---
'--- Get Computer name and current date
'---
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strFileDate = DatePart("yyyy",Now)  & Right("0" & DatePart("m",Now), 2)  & Right("0" & DatePart("d", Now), 2) 
logName = strComputerName & "_" & strFileDate & ".txt"

'---
'--- Delete existing file
'---
'wshShell.Run("%comspec% /c " & "DEL " & logName )


'---
'--- Run FCIV command
'---
strCommand = "fciv.exe -v -xml NCRTestFiles.xml >> " & logName

strErrorCode = wshShell.Run(strCommand,,True)

Select Case strErrorCode
     Case 0
        wshShell.LogEvent 0, "File Integrity App:  Test Passed."
     Case Else
        wshShell.LogEvent 1, "File Integrity App:  Test Failed."
end Select

Open in new window

David KnutsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Redirection is only available when running a program from the command interpreter, try the following change, I think this should work.

strCommand = "cmd /c fciv.exe -v -xml NCRTestFiles.xml >> " & logName

~bp
David KnutsonAuthor Commented:
Tried this -

strCommand = "cmd /c fciv.exe -v -xml NCRTestFiles.xml >> test.log"
strErrorCode = wshShell.Run(strCommand,,True)

But didn't create log file.
Bill PrewIT / Software Engineering ConsultantCommented:
Make sure you look in the proper folder for the output file, it will be the "current directory" at runtime of the vbs script, which may not be what you expect sometimes.  For a test try fully qualifying the log file with a full drive and path just to check this.

I ran this test here (since I don't have FCIV) and did indeed get the output to the file:

strCommand = "cmd /c systeminfo >> " & logName"

I ran my test from the command prompt, using CSCRIPT to run the vbs file, and the output with your naming convention was placed in that current directory I was in.

~bp
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

David KnutsonAuthor Commented:
Can you send me the batch and vbs files you created for the test.  Still can't get it to work - even when using your strcommand
Bill PrewIT / Software Engineering ConsultantCommented:
No BAT involved, I just ran from DOS command prompt as follows.

cscript EE28719199.vbs

Attached are the script, and the output file.

~bp
EE28719199.vbs
BP_20150922.txt
David KnutsonAuthor Commented:
Hmm.  Getting the following error when I run that

C:\Apps\MIS\Test>cscript test2.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Apps\MIS\Test\test2.vbs(25, 48) Microsoft VBScript compilation error: Unterminated string constant
David KnutsonAuthor Commented:
Changed line 25 to read

strCommand = "cmd /c fciv.exe -v -xml NCRTestFiles.xml >> " & logName

and now it works!  No idea why as I've tried this before.

Thanks!
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, good, glad we got past that.

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.