Computing.Net > Forums > Programming > VBScript help creating a log file

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VBScript help creating a log file

Reply to Message Icon

Original Message
Name: humerick
Date: June 9, 2006 at 10:57:41 Pacific
Subject: VBScript help creating a log file
OS: WinXP
CPU/Ram: Intel
Model/Manufacturer: Dell
Comment:

I am still very new to VBScript, and I need some help creating a log file that will show the output of an FTP. The reason that I need the log file is to later search through it for the string "Transfer complete". If I find it, then I know that the FTP worked. Below is a snip of my code. For some reason, the log file does not get written to. I also have a problem of the script continuing on before the FTP finishes. Is there a way to make the script wait until the FTP process is complete with out using the wait command?
The echoing of "found" and "not found" is only for troubleshooting purposes. If you need to see more of the code (ie.DIM), then just let me know. If you think that there is an easier way, I'm very open to making changes to the script.

Thanks in advance!
Scott

set objTextFile2 = fs.OpenTextFile("\\ntlifeprotest\workarea\cdpsxh\cmelog.txt",2,True)
Set wshshell = WScript.CreateObject("wscript.Shell")

retcode = Wshshell.run ("cmd /c ftp -s:cmeftp.scr "&strServer&" > objTextFile2",2,True)
'wscript.echo ("retcode = "&retcode)
objTextFile2.Close
'WScript.Sleep(100000) ' 10 second delay

Set objTextFile3 = fs.OpenTextFile("objTextFile2", 1)

Do Until objTextFile3.AtEndOfStream

strLine = objTextFile3.Readline

If InStr(strLine, "Transfer complete") <> 0 Then
wscript.echo strLine
wscript.echo "found"
else
wscript.echo strLine
wscript.echo "not found"
End If

Loop


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: June 9, 2006 at 13:07:38 Pacific
Reply: (edit)

Here's how I create and write to a log file:

Set objFSO = CreateObject("scripting.filesystemobject")
Set logStream = objFSO.createtextfile(logFile , True)
logStream.writeline "Text written into log file"
logStream.Close

You probably can use an echo, but your echos are not specifying "where" to echo to, so it makes sense there is nothing in your log files.

As for pausing execution of the script until the FTP process completes, the third parameter in the Wshshell.run command should pause the script until the Run command completes if it is set to true. Yours is set to true, so I don't know why it is not working.

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: humerick
Date: June 9, 2006 at 13:18:04 Pacific
Reply: (edit)

I somewhat understand what you are doing Michael, but how do I make the output from the FTP write to that file?


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: June 9, 2006 at 22:50:54 Pacific
Reply: (edit)

Don't know.

Michael J


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: June 11, 2006 at 00:02:28 Pacific
Reply: (edit)

I don't know VB but if I have a BAT, mybat, which does:

ftp -s:script

I can make a log with:

mybat > log


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software