| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Scripting - Client Side Discuss client-side scripting issues. Client-side scripting such as JavaScript, JScript, and VBScript as well as technologies such as HTML and stylesheets. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Writing wshell.exec to file cuts off
I have a script set up to execute certain command line programs over the network with psexec and dump the output to separate files. Everything appears to run properly, but the output is cut off in each file. It seems like when reading the stdout stream, it can only buffer a limited amount of text. Here is the part of my script where I execute the command and write it to a file:
Code:
set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Checking installed software..."
objFSO.CreateTextFile(strOutputDir & "installedsoftware.txt")
'''''Open the output file'''''
set objOutFile = objFSO.OpenTextFile(strOutputDir & "installedsoftware.txt", ForWriting)
'''''Run the utility'''''
set objExecObject = objShell.Exec(strExeDir & """" & strBaseDir & "\sysinternals\psinfo.exe"" -accepteula -s")
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
objOutFile.writeLine(strText)
Loop
objOutFile.Write Now
objOutFile.Close
When I run the command (psinfo.exe in this case) in cmd, I get: Quote:
Quote:
Last edited by PeejAvery; November 6th, 2009 at 11:40 PM. Reason: Major code/quote tag cleanup. |
|
#2
|
||||
|
||||
|
Re: Writing wshell.exec to file cuts off
You're making it rather hard on yourself. Why aren't you just reading the whole file rather than line by line?
Code:
Dim strFilePath, strFileContents
strFilePath = "C:\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFilePath, 1)
strFileContents = objTextFile.ReadAll()
Set objFSO = Nothing
Set objTextFile = Nothing
__________________
If the post was helpful...Rate it! Remember to use [code] or [php] tags. |
|
#3
|
|||
|
|||
|
Re: Writing wshell.exec to file cuts off
Quote:
![]() I'm running a program that outputs to the command line, and I want to capture that output and put it in a text file. However, it can only capture a limited amount of the output before it reaches the end of the stream. Right now, here is where I call Exec() in the shell object and then grab the output: Code:
[...] set objExecObject = objShell.Exec(strExeDir & """" & strBaseDir & "\sysinternals\psinfo.exe"" -accepteula -s") strText = objExecObject.StdOut.ReadAll() objOutFile.writeLine(strText) [...] |
|
#4
|
|||
|
|||
|
Re: Writing wshell.exec to file cuts off
I discovered that Stdout only has 8,000 bytes of buffer space, which may have been my issue. Instead, I decided to use the Run() method. However, I ran into issues with this as well until I found out you could do the following:
Code:
[...]
runCmd = strExeDir & """" & strBaseDir & "\sysinternals\psinfo.exe"" -accepteula -s > """ & strOutputDir & "installedsoftware.txt"""
return = objShell.Run("cmd /c """ & runCmd & """",1,true)
[...]
And just for further information, the full command being run was: Code:
"C:\Documents and Settings\magicked\Desktop\remote\sysinternals\psexec.exe" \\192.168.13.37 -u Administrator -p Password -c "C:\Documents and Settings\magicked\Desktop\remote\sysinternals\psinfo.exe" -accepteula -s > "C:\Documents and Settings\magicked\Desktop\remote\output\192.168.13.37\installedsoftware.txt" )I ran into trouble with Run(), because I didn't realize I had to put quotes around the whole runCmd. The script would ignore all my quotes around each path in the command otherwise, and it would error out with: Code:
'C:\Documents' is not recognized as an internal or external command, operable program or batch file. |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|