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

HTA: Read Command Line Output

1,283 views
Skip to first unread message

Tahir Ata Barry

unread,
Aug 25, 2006, 8:22:26 AM8/25/06
to
Hello Everybody

Can anyone tell me the code to read a commandline output in a .HTA file.
To elaborate it further, let me give you an example. If I type "dir" on
command prompt, it returns the list of files and folders. What I want is
to pass "dir" command on the shell and get the output in a variable that I
wil fill in a textarea.

This "dir" is just an example of what I want, not the actual application.
My actual application is a commandline software that returns a value on
the command line.

To be more specific, I do not want to write the output to a text file.
Just get it back in a variable. Further, I am looking for a solution for a
.HTA file and not for .vbs file. I could not find a newsgroup for .hta so
am posting this message here.

Thanks in advance!

Alexander Mueller

unread,
Aug 25, 2006, 10:53:40 AM8/25/06
to
Tahir Ata Barry schrieb:

> Hello Everybody
>
> Can anyone tell me the code to read a commandline output in a .HTA file.
> To elaborate it further, let me give you an example. If I type "dir" on
> command prompt, it returns the list of files and folders. What I want is
> to pass "dir" command on the shell and get the output in a variable that
> I wil fill in a textarea.
>
> This "dir" is just an example of what I want, not the actual
> application.. My actual application is a commandline software that
> returns a value on the command line.
>
> To be more specific, I do not want to write the output to a text file.
> Just get it back in a variable. Further, I am looking for a solution for
> a ..HTA file and not for .vbs file. I could not find a newsgroup for
> .hta so am posting this message here.


You might run the command under the control of a WshShellExec-object
which has access to stdout, stderr and stdin.
As for console-windows there is afaik no way to hide them using
WshShell.Exec.

MfG,
Alex


'if you only want to process *one* shell-cmd
'use cmd with the /c switch so it quits when work is done:

Set ws = CreateObject("WScript.Shell")
set cmd = ws.Exec("cmd /c cd /d C:\ & dir")
ws.popup cmd.stdout.readall 'get+show output

'if you want to process *multiple* shell-cmd
'use cmd with the /k switch, which opens it as a session.
'So you can exec shell-cmds be writing lines to stdin:


Set ws = CreateObject("WScript.Shell")
set cmd = ws.Exec("cmd /k")
cmd.stdin.writeline("cd /d %windir%") 'nav to windir
cmd.stdin.writeline("dir") 'list files
cmd.stdin.writeline("cd \") 'nav to root
cmd.stdin.writeline("dir") 'list files
cmd.stdin.close 'close stdin [can't reopen!]
'-> sets EOF to stdout
ws.popup cmd.stdout.readall 'get+show output

phpMax

unread,
Aug 25, 2006, 3:13:38 PM8/25/06
to
Thanks! The code is perfect! One thing I want to ask if you can help in
that as well. When the code runs, I can see the command window flashing
for a fraction of a second. Is there a way that this window does not
appear.

Thanks again!

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Csaba Gabor

unread,
Aug 25, 2006, 9:46:16 PM8/25/06
to
phpMax wrote:
> Thanks! The code is perfect! One thing I want to ask if you can help in
> that as well. When the code runs, I can see the command window flashing
> for a fraction of a second. Is there a way that this window does not
> appear.
>
> Thanks again!

For a single file solution, see the the 8th post of the following
thread:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/54d3df2e29211bad/

Csaba

0 new messages