Beginner's questions: running programs
- From: Paul Emmons <pemmons@xxxxxxxxxxxx>
- Date: Thu, 07 Jul 2005 23:45:35 GMT
I'm currently interested in learning vbscript for the same purposes as
batch language: manipulating files and running programs from a DOS
prompt.
The following code performs DIR and shows the output. Is this a good
pattern for most non-interactive DOS programs, or is there a simpler
or more efficient way? To be complete, a similar loop would be needed
for stderr output as well, and I haven't even experimented with stdin
yet:
------------------------
' For use with cscript
' Demonstrates how to run a command-line program and show its output
' without opening a new window
Dim oWsh, oX
Set oWsh = Wscript.CreateObject("Wscript.Shell")
set oX = oWsh.exec("%comspec% /C dir")
Do until oX.stdOut.AtEndOfstream
Wscript.echo oX.stdout.readline()
loop
------------------------
If the DOS program returns an errorlevel code, how is that accessed?
Another question (and this is a real reason for learning an
alternative to batch):
I have a batch file that runs a MS-Access macro (among other
tasks). This line is:
C:\Progra~1\Micros~1\Office\MSACCESS ttf /xdupcrcs
(ttf is the database and dupcrcs is the name of the macro).
It runs fine on my machine except that when Access
finishes, I'm returned to the desktop rather than
the DOS window, and the batch file does not continue.
How would I start up Access in VBscript, run that macro, and continue
the script without any interruptions?
In general, what book or web site would you recommend studying for
this kind of use of VBscript? I have _VBScript_in_a_Nutshell_, which
is indispensible but sketchy; and _VBScript_ 2nd ed. by Adrian
Kingsley-Hughes et al. (published by Wrox). This book is
altogether disappointing: badly organized and sometimes
poorly written and with errors. It concentrates on clients, servers,
COM objects, and Web applications. That is all irrelevant for me just
now. I'd like to find something more detailed and elementary for my
present needs.
Thank you!
.
- Follow-Ups:
- Re: Beginner's questions: running programs
- From: James Whitlow
- Re: Beginner's questions: running programs
- Prev by Date: Re: EnCrypt
- Next by Date: Submitting Data from a form to Excel Worksheet
- Previous by thread: EnCrypt
- Next by thread: Re: Beginner's questions: running programs
- Index(es):
Relevant Pages
|