• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

Read text from text mode (VIO) application or command

Started by jep, 2008.04.22, 13:47:57

Previous topic - Next topic

jep

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.

/* 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

warpcafe

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
"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

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