Link to home
Create AccountLog in
Avatar of David Knutson
David Knutson

asked on

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

Avatar of Bill Prew
Bill Prew

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

Avatar of David Knutson


Tried this -

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

But didn't create log file.
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.

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
No BAT involved, I just ran from DOS command prompt as follows.

cscript EE28719199.vbs

Attached are the script, and the output file.

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
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.

Avatar of Bill Prew
Bill Prew

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account