Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using objShell.Exec

Status
Not open for further replies.

mivey4

Programmer
Dec 8, 2006
10
US
Hi.

I have written a program in vbscript to capture the console output and write it to a file. My problem is that it is only capturing the last line of output for a particular program. But if I execute a simple command like DIR /B, I get the full output written to my file.

My initial thoughts were that this particular program isn't outputting to the console by line but maybe through an array of values in the background which may explain why I am only getting the last line.

HERE IS MY CODE SAMPLE USING DIR /B: (THIS WORKS USING THE DIR COMMAND BUT NOT JFTP)

Dim consoleOutput, objshell, objScriptExec, FSO, consoleOutput, results

Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("dir /b")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set consoleOutput = FSO.OpenTextFile("ftp_audit_log.txt", 8, True)

results = objScriptExec.StdOut.ReadAll
Do While Not objScriptExec.StdOut.AtEndOfStream
results = objScriptExec.StdOut.ReadLine()
consoleOutput.WriteLine(results)
'WScript.Echo results
Loop


consoleOutput.Close
SET consoleOutput = NOTHING
SET FSO = NOTHING

If it helps, the program I am trying to capture the output for is jftp.

Has anyone seen a similar issue like this or have any suggestions that may be able to help me out???

Thanks
 
perhaps a wshshell.run cmd /c ..... > totextfile.txt would make life easier?
 
Thanks for the posted reply mrmovie but I've already been down that road. :)

This jftp program simply ignores redirects to files of any type thats why I am using the alternate method of capturing the output with StdOut. Which does get me further along except for the fact that its only giving me the last line back.

Any other ideas???
 
does commenting out "results = objScriptExec.StdOut.ReadAll" have a positive effect?
perhaps this method call is what is causing you to loose the information?
 
Not all applications that write to the console do so via the standard streams, which makes them difficult to redirect or to capture.
 
mrmovie,

I commented out the results variable as you suggested but it didn't make any difference in the results. Thanks though.

strongm,

your reply suggests that maybe you've seen this type of issue before? If so, do you have a recommendation for resolve?

I guess I understand somewhat of what you're saying, but if the standard stream isn't being used; why would I be able to capture the last line of the output using stdout???

Thanks
 
>do you have a recommendation for resolve?

I am not aware of a method of capturing non-stream console output in VBScript, I'm afraid.

>why would I be able to capture the last line of the output using stdout???

Because they may be using a mixture of output methods.

I'm afraid I'm not familiar with JFTP (and Google suggests that there are quite a number of programs with this name), so cannot comment on how your particular application actually works.
 
What you have done on stdout, repeat the same for stderr: whether you write to the same log file or another file, it is up to you. In the cmd/bat language, it is about the same as saying
[tt] 1>ftp_audit_log.txt 2>&1[/tt]
or
[tt] 1>ftp_audit_log.txt 2>ftp_audit_log2.txt[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top