OS2 World.Com Forum
2012.05.26, 00:14:32 *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Read text from text mode (VIO) application or command  (Read 1431 times)
jep
Global Moderator
Sr. Member
*****
Posts: 402


View Profile
« on: 2008.04.22, 13:47:57 »

Marked as: Easy
Hello,

Some text mode applications doesn't send output to stdout, but rather to stderr, or even both mixed togheter and it can be difficult to get the right data. The function SysTextScreenRead can then be quite handy, but you can only get data from the screen that is visible.

Code:
/* Read text from text mode application or command */
'@ECHO OFF'

CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
CALL SysLoadFuncs


'@DISKINFO -I'
PARSE VALUE SysCurPos() WITH row col
line = SysTextScreenRead( row - 2, 0, 80 ) /* Reading revious line */
CALL SysCurPos row, col

PARSE VALUE line WITH .'='speed .'='speed2
SAY speed
SAY speed2
Logged
warpcafe
Global Moderator
Hero Member
*****
Posts: 746


Failure is not an option.


View Profile
« Reply #1 on: 2008.04.22, 16:09:07 »

Hey jep,

short side-note:
One can always check, if an application "correctly" supports redirection - namely "redirection of stderr to stdout" by using the output "channel numbers" method.
"1" is for stdout, "2" is for stderr, thus...

someprog 2>&1

...will redirect stderr to stdout. Except if "someprog" is not using real "std"outputs but hand-crafted fake methods. Also, redirection to file works accordingly:

someprog > logfile.txt 2>&1

...will redirect stdout to "logfile.txt" and stderr to where stdout goes.
Cheers!

Thomas
Logged

"It is not worth an intelligent man's time to be in the majority.
By definition, there are already enough people to do that"
- G.H. Hardy
jep
Global Moderator
Sr. Member
*****
Posts: 402


View Profile
« Reply #2 on: 2008.04.22, 17:42:09 »

Hello,

Quite right... redirection of stdout and stderr is quite useful and most of the time also the approach to use.
When the app doesn't allow redirection with parameters such as 2>&1 then you may want to try the other method though. I once tried a tool to unpack xdf disks that behaved in that way... either it ran without those params or exited right away.

Summary:
  • Use redirection (2>&1 etc.) if you want to handle all of the output.
  • Use SysTextScreenRead(...) if you want to get only the last few lines or the app doesn't support redirection.

//Jan-Erik
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!