如何使用批处理文件将我的 vbscript 输出重定向到文件? [英] How can I redirect my vbscript output to a file using batch file?

查看:35
本文介绍了如何使用批处理文件将我的 vbscript 输出重定向到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Windows 脚本的新手.我有一个使用 WinRAR CLI 实用程序进行归档的简单脚本.我必须使用批处理文件来安排这个脚本.在归档期间存在一些错误,我希望它们写入一个简单的文本文件,或者至少我可以将归档的整个输出写入一个文件中.如何更改我的代码以执行此操作?

I am new to Windows Scripting. I have a simple script for archiving using WinRAR CLI utility. I have to schedule this script using batch file. During archiving there are some errors and I want them to write in a simple text file or at least I can write entire output of archiving in a file. How can I change my code to do this?

Dim MyDate
Dim OutputFile 
const WaitUntilFinished = true, DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0 

MyDate = Replace(Date, "/", "-")
OutputFile = "backup-" & mydate & ".rar" 

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = "C:\Users\ABC\Desktop\"
objShell.Run "C:\windows\Rar.exe a .\VBScripts\backups\" & OutputFile & " software", ShowWindow, WaitUntilFinished

objShell.Popup "Archiving Completed Successfully!",5, "Scheduled Backup"
Set objShell = Nothing

批处理文件是这样的;

@echo off 
start /wait C:\Users\ABC\Desktop\VBScripts\scheduled_backup.vbs 

推荐答案

更改命令行以包括重定向到日志文件:

Change your command line to include redirection to a log file:

logfile = "C:\path\to\your.log"
objShell.Run "%COMSPEC% /c C:\windows\Rar.exe a .\VBScripts\backups\" & _
  OutputFile & " software >""" & logfile & """", ShowWindow, WaitUntilFinished

这篇关于如何使用批处理文件将我的 vbscript 输出重定向到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆