allen2, on 08 August 2011 - 11:54 PM, said:
You need :
- to comment the line
RunMeWithCScript()
- to comment all lines with wscript.echo (unless you want popup for each line).
- to launch the script with wscript.exe instead of cscript if you're launching it from another script.
I've finally managed to make the script fully silent. Thanks,
allen2
This is what I did.
1) I commented the following lines:
WScript.Echo "usage: YankLines <input_filename> <output_filename>"
WScript.Echo("Record: " & strFirstField)
wscript.Echo "Total Records Writen: " & objDict.count
wscript.Echo "Total Duplicates found: " & j
and then changed:
If scriptEngine = "WSCRIPT.EXE" Then
to
If scriptEngine = "CSCRIPT.EXE" Then
After doing so there's no visible output anymore.
This is a shrunken version of the whole script (all comments removed & case insensitive):
RunMeWithCScript()
If WScript.Arguments.Count <> 2 then
WScript.Quit
end If
Const ForReading = 1, ForWriting = 2
Dim i, j
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(WScript.Arguments.Item(0), ForReading)
Set objOutputFile = objFSO.OpenTextFile (WorkingDir & WScript.Arguments.Item(1), ForWriting, True)
Set objDict = CreateObject("Scripting.Dictionary")
objDict.CompareMode = 1
j = 0
On Error Resume Next
While Not objInputFile.AtEndOfStream
arrinputRecord = split(objInputFile.Readline, "vbNewLine")
strFirstField = arrinputRecord(0)
If objDict.Exists(strFirstField) then
j=j+1
Else
objDict.add strFirstField, strFirstField
End If
Wend
colKeys = objDict.Keys
For Each strKey in colKeys
objOutputFile.writeline objDict.Item(strKey)
Next
objInputFile.Close
objOutputFile.Close
Public Sub RunMeWithCScript()
Dim scriptEngine, engineFolder, Args, arg, scriptName, argString, scriptCommand
scriptEngine = Ucase(Mid(Wscript.FullName,InstrRev(Wscript.FullName,"\")+1))
engineFolder = Left(Wscript.FullName,InstrRev(Wscript.FullName,"\"))
argString = ""
If scriptEngine = "CSCRIPT.EXE" Then
Dim Shell : Set Shell = CreateObject("Wscript.Shell")
Set Args = Wscript.Arguments
For each arg in Args
If instr(arg," ") > 0 Then arg = """" & arg & """"
argString = argString & " " & Arg
Next
scriptCommand = "cmd.exe /c " & engineFolder & "cscript.exe //U """ & Wscript.ScriptFullName & """" & argString
Shell.Run scriptCommand,,False
Wscript.Quit
Else
Exit Sub
End If
End Sub
This post has been edited by tomasz86: 20 July 2012 - 01:42 AM