Re: Need suggestion how to hide ugly black command prompt window by Drazen
Drazen
Sat Jul 15 01:54:30 CDT 2006
Exactly what I needed, thank you Tom!
Tom Lavedas je napisao/la:
> The most common approach is to use the Wscript.Shells Run method
> instead with its second parameter set to zero and redirect the output
> into a temporary file (requires invoking the command processor) and
> then read & delete the output file.
>
> I wrote a little function to implement this approach a long time ago,
> as follows:
>
> --------------------8<----------------------------
> Function CmdPrompt(sCmd)
> Dim alines, sCmdLine, stemp, ofs, oWS, nRes
> 'On Error Resume Next
> sCmdLine = """%comspec%"" /c " & sCmd & " >> "
> set ofs = CreateObject("Scripting.FileSystemObject")
> stemp = ofs.GetTempName
> set oWS = CreateObject("Wscript.Shell")
> stemp = oWS.Environment("PROCESS")("TEMP") & "\" & stemp
> nRes = oWS.Run(sCmdLine & Chr(34) & sTemp & Chr(34) & " 2>>&1" _
> , 0, True)
> alines = "ERRORLEVEL: " & nRes & vbCRLF
> if ofs.FileExists(sTemp) Then
> with ofs.OpenTextFile(stemp)
> if Not .AtEndofStream Then
> alines = aLines & .ReadAll
> End if
> End With
> ofs.DeleteFile stemp
> alines = Split(aLines, vbNewline)
> Else
> aLines = Array(nRes, "")
> End if
> ReDim Preserve alines(Ubound(alines) - 1)
> if Err.Number <> 0 Then _
> aLines = Array("Error Number:" & CStr(Err.Number), Err.Description)
> CmdPrompt = alines
> End Function
> -----------------------8<------------------------
>
> It returns an array, where each element of the array is a line of text
> from the command console output. The first element of the returned
> array is the error level returned
> Jim wrote:
> > if all youre doing is copying files, why not just use the file copy methods
> > available to vbscript??
> > then you dont have to deal with command windows period
> >
> >
> > <delfincek28@gmail.com> wrote in message
> > news:1152787238.263662.112090@s13g2000cwa.googlegroups.com...
> > >
> > > There are some scripts we use for transfering data, and they look
> > > something like this:
> > >
> > > ...
> > >
> > > Function CMDResults(cmdline)
> > > Set oShell = CreateObject("WScript.Shell")
> > > Set oExCmd = oShell.Exec(cmdline)
> > > Set oExCmdStdOut = oExCmd.StdOut
> > >
> > > Do: WScript.Sleep 10
> > > Do Until oExCmdStdOut.AtEndOfStream
> > > CmdResults = CmdResults & oExCmdStdOut.ReadAll
> > > Loop
> > > Wscript.Sleep 1000
> > > Loop Until (oExCmd.Status <> 0 and oExCmdStdOut.AtEndOfStream)
> > > Logiraj cmdline
> > > Logiraj CMDResults
> > > End Function
> > >
> > > ...main program starts here...
> > >
> > > Do While Not (txtStream.atEndOfStream)
> > > Linija = txtStream.ReadLine
> > > sExec = "cmd /c copy X:\transfer\tra\out\" & Linija & " c:\tran\S" &
> > > p_sifra & "\PRIHVAT /Y" & Chr(13) & Chr(10)
> > > sResult = CMDResults(sExec)
> > > If InStr(1,LCase(sresult),"1 file(s) copied") > 0 Then
> > > ...what to do if copying a file succeded...
> > > End If
> > > Loop
> > > Set oFSO = Nothing
> > > ...
> > >
> > > What this script does it copy file via plain "cmd /c copy" and retrieve
> > > result, so if result incorporates "1 file(s) copied" then copying a
> > > file if considered success, otherwise not.
> > > The problem is with this ugly black command prompt that pops up.
> > > Is there a way i can hide the command prompt window or could I have
> > > done this some other way?
> > >
> > > Thank you,
> > > Drazen
> > >