We help IT Professionals succeed at work.

VBS script output

David Knutson
on
211 Views
Last Modified: 2015-09-28
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

Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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

Author

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 PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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

Author

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 PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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

Author

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

Author

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!
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.