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

VB ScriptPHP

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
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

~bp
David Knutson

ASKER
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 Prew

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
David Knutson

ASKER
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 Prew

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 Knutson

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
David Knutson

ASKER
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!
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.