Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Redirecting stdout in WScript.run ?

94 views
Skip to first unread message

Marianne Anderson

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
I'd like to be able to redirect the output from a command run from a
WScript.run
E.g.

sort <foo.txt >bar.txt works when I type it at a DOS prompt, but fails
in a script. Anyone got an idea how I can do this?

Marianne


Michael Harris

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Shell.Run "%comspec% /c sort <foo.txt >bar.txt",0,true

--
Michael Harris
Marianne Anderson <marianne...@digital.com> wrote in message news:37D7CED1...@digital.com...

Michael Harris

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
This is such a common question/problem, an explanation is probably in order.
 
You have to think of Windows as having two "command line" environments:
  • the standard console window (aka, DOS box).
  • the other represented visually by the Windows Run dialog box.  The WScript.Shell's Run method is (logically speaking) the non-visual counterpart of the Windows Run dialog.
A command like "sort <c:\foo.txt >c:\bar.txt" won't work from either variation of the "Windows command line" because the "Windows command line" doesn't support redirection.  Only the "console window" command line supports redirection.
 
To illustrate, create c:\foo.txt (with several unsorted arbitrary lines) and try entering the following command in the Windows Run dialog:
 
sort <c:\foo.txt >c:\bar.txt
 
The console window flashes by, but no c:\bar.txt file is created.
 
Now try:
 
%comspec% /c sort <c:\foo.txt >c:\bar.txt
 
Again, the console window flashes by, but this time c:\bar.txt file _is_ created.

--
Michael Harris

Marianne Anderson

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Thanks Michael!

I didn't really see a good explanation of this in the documentation I
have. This was
exactly what I needed to make sense of things.

Marianne

Michael Harris wrote:

> This is such a common question/problem, an explanation is probably in
> order. You have to think of Windows as having two "command line"
> environments:
>

> * the standard console window (aka, DOS box).
> * the other represented visually by the Windows Run dialog box.


> The WScript.Shell's Run method is (logically speaking) the
> non-visual counterpart of the Windows Run dialog.
>
> A command like "sort <c:\foo.txt >c:\bar.txt" won't work from either
> variation of the "Windows command line" because the "Windows command
> line" doesn't support redirection. Only the "console window" command
> line supports redirection. To illustrate, create c:\foo.txt (with
> several unsorted arbitrary lines) and try entering the following
> command in the Windows Run dialog: sort <c:\foo.txt >c:\bar.txt The
> console window flashes by, but no c:\bar.txt file is created. Now
> try: %comspec% /c sort <c:\foo.txt >c:\bar.txt Again, the console
> window flashes by, but this time c:\bar.txt file _is_ created.
> --
> Michael Harris
>
> Michael Harris <Please...@To.Group> wrote in message
> news:umTeleu##GA....@cppssbbsa02.microsoft.com...Shell.Run
> "%comspec% /c sort <foo.txt >bar.txt",0,true
> --
> Michael Harris
>
> Marianne Anderson <marianne...@digital.com>
> wrote in message

> news:37D7CED1...@digital.com...I'd like to

Mitchell C. Sharp

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Use CScript

- ed lin

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
WSH Version 2, Beta 2 allows redirection of console commands and
applications (gives you handles on the pipes).

0 new messages