|
|
Execute command line program and capture output
Some might find this useful.
Lee
/* test_shellexec.rex */
WshShell = .oleObject~new("WScript.Shell")
oExec = WshShell~Exec("ping www.rexxla.org")
do while oExec~Status = 0
call SysSleep(1)
end
strOutput = oExec~StdOut~ReadAll
strError = oExec~StdErr~ReadAll
say strOutput
say '---'
say strError
|
|
0
|
|
|
|
Reply
|
Lee
|
11/3/2005 6:09:27 PM |
|
In article <8gkkm114nr15jgjughg32521br2emg1uin@4ax.com>,
lpeedinREMOVE@UPPERCASEnc.rr.com says...
> Some might find this useful.
> Lee
>
> /* test_shellexec.rex */
> WshShell = .oleObject~new("WScript.Shell")
> oExec = WshShell~Exec("ping www.rexxla.org")
> do while oExec~Status = 0
> call SysSleep(1)
> end
>
> strOutput = oExec~StdOut~ReadAll
> strError = oExec~StdErr~ReadAll
>
> say strOutput
> say '---'
> say strError
>
>
Thanks Lee, this is what I needed. It even works when started from a DB2
Command Window and running DB2 commands. I was afraid the
..oleObject~new("WScript.Shell") command creates a new environment but it
inherites the DB2 Command Window environment which is what I needed.
Another reason to force the customer to install at least Object REXX
2.1.3, they are still running with 1.0.3.
Kind regards, Gert
|
|
0
|
|
|
|
Reply
|
Gert
|
11/4/2005 8:32:02 AM
|
|
Lee Peedin wrote:
> Some might find this useful.
> Lee
>
> /* test_shellexec.rex */
> WshShell = .oleObject~new("WScript.Shell")
> oExec = WshShell~Exec("ping www.rexxla.org")
> do while oExec~Status = 0
> call SysSleep(1)
> end
>
> strOutput = oExec~StdOut~ReadAll
> strError = oExec~StdErr~ReadAll
>
> say strOutput
> say '---'
> say strError
Or the ANSI standard way of doing it with Regina :-)
/* */
Address System 'ping www.rexxla.org' With Output Stem out. Error Stem
err.
Do i = 1 To out.0
Say out.i
End
Say '---'
Do i = 1 To err.0
Say err.i
End
|
|
0
|
|
|
|
Reply
|
markh
|
11/4/2005 10:28:49 AM
|
|
In article <1131100129.349849.53820@o13g2000cwo.googlegroups.com>,
rexx@users.sourceforge.net says...
>
> Lee Peedin wrote:
> > Some might find this useful.
> > Lee
> >
> > /* test_shellexec.rex */
> > WshShell = .oleObject~new("WScript.Shell")
> > oExec = WshShell~Exec("ping www.rexxla.org")
> > do while oExec~Status = 0
> > call SysSleep(1)
> > end
> >
> > strOutput = oExec~StdOut~ReadAll
> > strError = oExec~StdErr~ReadAll
> >
> > say strOutput
> > say '---'
> > say strError
>
> Or the ANSI standard way of doing it with Regina :-)
>
> /* */
> Address System 'ping www.rexxla.org' With Output Stem out. Error Stem
> err.
> Do i = 1 To out.0
> Say out.i
> End
> Say '---'
> Do i = 1 To err.0
> Say err.i
> End
>
Please add this to ooRexx :)
|
|
0
|
|
|
|
Reply
|
Gert
|
11/4/2005 10:31:37 AM
|
|
In article <8gkkm114nr15jgjughg32521br2emg1uin@4ax.com>,
lpeedinREMOVE@UPPERCASEnc.rr.com says...
> Some might find this useful.
> Lee
>
> /* test_shellexec.rex */
> WshShell = .oleObject~new("WScript.Shell")
> oExec = WshShell~Exec("ping www.rexxla.org")
> do while oExec~Status = 0
> call SysSleep(1)
> end
>
> strOutput = oExec~StdOut~ReadAll
> strError = oExec~StdErr~ReadAll
Lee,
Running the script below works on XP Home but hangs on Windows 2K.
It looks like oExec~Status remains 0. If I remove the first do-while
loop it runs without a problem. Any idea what's causing this 'problem'?
Kind regards, Gert
WshShell = .oleObject~new("WScript.Shell")
oExec = WshShell~Exec("db2 list database directory")
do while oExec~Status = 0
call SysSleep(1)
end
do while oExec~StdOut~AtEndOfStream = 0
say oExec~StdOut~ReadLine
end
exit
|
|
0
|
|
|
|
Reply
|
Gert
|
11/7/2005 7:29:41 PM
|
|
Gert,
The oExec~Status should remain at 0 as long as the Exec is running.
You can see this by taking my original example and change the
following:
oExec = WshShell~Exec("ping www.rexxla.org")
to
oExec = WshShell~Exec("calc")
You'll see that the status remains 0 until you close the calculator.
I'm reasonably sure you can remove the "do while" loop and be OK.
Lee
On Mon, 7 Nov 2005 20:29:41 +0100, Gert van der Kooij
<nomail@nl.invalid> wrote:
>In article <8gkkm114nr15jgjughg32521br2emg1uin@4ax.com>,
>lpeedinREMOVE@UPPERCASEnc.rr.com says...
>> Some might find this useful.
>> Lee
>>
>> /* test_shellexec.rex */
>> WshShell = .oleObject~new("WScript.Shell")
>> oExec = WshShell~Exec("ping www.rexxla.org")
>> do while oExec~Status = 0
>> call SysSleep(1)
>> end
>>
>> strOutput = oExec~StdOut~ReadAll
>> strError = oExec~StdErr~ReadAll
>
>
>Lee,
>Running the script below works on XP Home but hangs on Windows 2K.
>It looks like oExec~Status remains 0. If I remove the first do-while
>loop it runs without a problem. Any idea what's causing this 'problem'?
>
>Kind regards, Gert
>
>
>WshShell = .oleObject~new("WScript.Shell")
>oExec = WshShell~Exec("db2 list database directory")
>
>do while oExec~Status = 0
> call SysSleep(1)
>end
>
>do while oExec~StdOut~AtEndOfStream = 0
> say oExec~StdOut~ReadLine
>end
>exit
|
|
0
|
|
|
|
Reply
|
Lee
|
11/7/2005 8:00:08 PM
|
|
In article <9ccvm1l9f28t064t5d96mrg9k4ieoqkoh7@4ax.com>, Lee Peedin
(lpeedinREMOVE@UPPERCASEnc.rr.com) says...
> Gert,
> The oExec~Status should remain at 0 as long as the Exec is running.
> You can see this by taking my original example and change the
> following:
> oExec = WshShell~Exec("ping www.rexxla.org")
> to
> oExec = WshShell~Exec("calc")
>
> You'll see that the status remains 0 until you close the calculator.
>
> I'm reasonably sure you can remove the "do while" loop and be OK.
>
> Lee
Thanks Lee,
I removed the 'do while oExec~Status = 0' loop and it worked wihout a
problem. Do you know if it's possible to display all methods and
properties of the 'oExec' object?
TIA, Gert
|
|
0
|
|
|
|
Reply
|
Gert
|
11/12/2005 6:55:37 PM
|
|
In article <MPG.1de0591031f6ef6e9898b0@news.xs4all.nl>, Gert van der
Kooij (gert@invalid.nl) says...
>
> Thanks Lee,
>
> I removed the 'do while oExec~Status = 0' loop and it worked wihout a
> problem. Do you know if it's possible to display all methods and
> properties of the 'oExec' object?
>
> TIA, Gert
>
I found it allready, all properties are listed at
http://tinyurl.com/con8m
|
|
0
|
|
|
|
Reply
|
Gert
|
11/12/2005 7:09:44 PM
|
|
|
7 Replies
388 Views
(page loaded in 0.09 seconds)
|
|
|
|
|
|
|
|
|