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

Re: Need suggestion how to hide ugly black command prompt window by Csaba

Csaba
Thu Jul 13 06:58:21 CDT 2006

delfincek28@gmail.com wrote:
> There are some scripts we use for transfering data, and they look
> something like this:

...

> 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?

In place of .Exec, you can use .Run where the second argument is
0 (for hidden cmd window) and the third argument is 1 (for
synchronous = wait until command is finished). Not sure what
file copy returns (as far as .Run goes) - you may need to check file
dates or existence.

Csaba Gabor from New York


Re: Need suggestion how to hide ugly black command prompt window by Jim

Jim
Thu Jul 13 09:21:41 CDT 2006

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
>



Re: Need suggestion how to hide ugly black command prompt window by Drazen

Drazen
Fri Jul 14 08:33:12 CDT 2006


No that was just an example, we use CMDresutls function for other
things too.
The point is to retrieve the result without black command prompt
window.

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
> >


Re: Need suggestion how to hide ugly black command prompt window by Tom

Tom
Fri Jul 14 12:46:27 CDT 2006

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
> >


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
> > >