From: bob123 on
Hi,

I would like to execute an OS command
from a list of databases in liste.txt
and get all the results in a file liste.out.
How can I do that ?

Below my first "code"
I see a cmd quick opened but nothing else
Thanks for your help ...


Dim fso, infile, aNames, sBase, shell
set fso = createobject("scripting.filesystemobject")
set infile = fso.opentextfile("liste.txt",1)
Set shell = WScript.CreateObject("WScript.Shell")

aNames = Split(infile.readall, vbnewline)
infile.close

for each sBase in aNames
wsh.echo "Base:", sBase
shell.Run "tnsping sBase"
Next


From: Richard Mueller [MVP] on

"bob123" <bob123(a)gmail.com> wrote in message
news:4bae0620$0$22393$426a74cc(a)news.free.fr...
> Hi,
>
> I would like to execute an OS command
> from a list of databases in liste.txt
> and get all the results in a file liste.out.
> How can I do that ?
>
> Below my first "code"
> I see a cmd quick opened but nothing else
> Thanks for your help ...
>
>
> Dim fso, infile, aNames, sBase, shell
> set fso = createobject("scripting.filesystemobject")
> set infile = fso.opentextfile("liste.txt",1)
> Set shell = WScript.CreateObject("WScript.Shell")
>
> aNames = Split(infile.readall, vbnewline)
> infile.close
>
> for each sBase in aNames
> wsh.echo "Base:", sBase
> shell.Run "tnsping sBase"
> Next
>
>

If the value of variable sBase is a parameter passed to the program tnsping,
the value must be concatenated to the name of the utility, making sure to
leave a space. For example:

shell.Run "tnsping " & sBase

Better yet is to specify the command processor, have the application run
minimized, and wait it to complete. For example:

iReturn = shell.Run("%comspec% /c tnsping " & sBase, 2, True)

If the value of iReturn is 0, the command ran without errors. To redirect
the output of each tnsping command to a text file, you could use something
similar to:

iReturn = shell.Run("%comspec% /c tnsping " & sBase & " >> liste.out", 2,
True)

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


From: bob123 on
>
> shell.Run "tnsping " & sBase
>
> Better yet is to specify the command processor, have the application run
> minimized, and wait it to complete. For example:
>
> iReturn = shell.Run("%comspec% /c tnsping " & sBase, 2, True)

Ok thanks
By the way, what is the signification of 2 and True ?


From: bob123 on
How can I put the current sBase
in the file liste.out before running the cmd

Thanks again



From: Al Dunbar on


"Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in
message news:unx9G9bzKHA.2552(a)TK2MSFTNGP04.phx.gbl...
>
> "bob123" <bob123(a)gmail.com> wrote in message
> news:4bae0620$0$22393$426a74cc(a)news.free.fr...
>> Hi,
>>
>> I would like to execute an OS command
>> from a list of databases in liste.txt
>> and get all the results in a file liste.out.
>> How can I do that ?
>>
>> Below my first "code"
>> I see a cmd quick opened but nothing else
>> Thanks for your help ...
>>
>>
>> Dim fso, infile, aNames, sBase, shell
>> set fso = createobject("scripting.filesystemobject")
>> set infile = fso.opentextfile("liste.txt",1)
>> Set shell = WScript.CreateObject("WScript.Shell")
>>
>> aNames = Split(infile.readall, vbnewline)
>> infile.close
>>
>> for each sBase in aNames
>> wsh.echo "Base:", sBase
>> shell.Run "tnsping sBase"
>> Next
>>
>>
>
> If the value of variable sBase is a parameter passed to the program
> tnsping, the value must be concatenated to the name of the utility, making
> sure to leave a space. For example:
>
> shell.Run "tnsping " & sBase
>
> Better yet is to specify the command processor, have the application run
> minimized, and wait it to complete. For example:
>
> iReturn = shell.Run("%comspec% /c tnsping " & sBase, 2, True)
>
> If the value of iReturn is 0, the command ran without errors. To redirect
> the output of each tnsping command to a text file, you could use something
> similar to:
>
> iReturn = shell.Run("%comspec% /c tnsping " & sBase & " >> liste.out", 2,
> True)

In addition to those suggestions, I would also recommend that an explicit
path to the working files be made explicit, either by giving them literally
(i.e. "C:\my script\liste.txt"), or calculating them from some reference
point such as where the script file itself is located.

As written, your script relies on the default folder being the one
containing these files. While this might work in your testing environment,
if there is a possibility that the process for starting the scripts might be
different (i.e. double-clicking, versus calling from a cmd prompt window
where its location is on the PATH, versus running it from an HTA...), the
additional work done to make it a little less susceptible to such issues
could be worth it.


/Al