Author Topic: redirect stdout, stderr and stdin  (Read 5080 times)

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 275
  • Karma: +5/-0
    • View Profile
redirect stdout, stderr and stdin
« on: July 28, 2021, 09:31:41 pm »
Hello,

would like to run one vio application at the time in a separate thread and redirect stdout, stderr and stdin to control it. Tried variations to the example found in "IBM Developers Toolkit version 4.5", "Control Program Programming Giude and Reference", "Redirecting Standard I/O for Child Processes".

The example only describe how to do it for stdout, but I've found examples that include stderr or stdin, but not quite the way intended here.

sqlite3.exe would be a great example.
One can start it and enter a command, wait for the output and then enter a new command (sql query) and continue, and not just a command at startup.

One would be able to write the support library required for oosqlite and Open Object Rexx 5.0.0 on OS/2-ArcaOS.  ;)

See attachment... Please do tell how it should be written instead.

//Jan-Erik

Rich Walsh

  • Sr. Member
  • ****
  • Posts: 331
  • Karma: +23/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: redirect stdout, stderr and stdin
« Reply #1 on: July 29, 2021, 09:24:16 pm »
I've attached a sample function that should redirect stdIn/Out/Err to 3 pipes. I haven't tested it.

Note that its style is extremely simple. Until something you're unfamiliar with is actually working, optimization and excess cleverness just get in the way.

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 275
  • Karma: +5/-0
    • View Profile
Re: redirect stdout, stderr and stdin
« Reply #2 on: August 09, 2021, 11:13:00 am »
Thank you for the code.

I've tried it out as well as the original code with different variations.

redirecting stdout and stderr is no problem as it seem, it's when I want to add redirection of stdin that things stop working.

Regards,
//Jan-Erik

Andy Willis

  • Sr. Member
  • ****
  • Posts: 292
  • Karma: +7/-0
    • View Profile
Re: redirect stdout, stderr and stdin
« Reply #3 on: August 10, 2021, 04:52:46 am »
I added stdin to voix some years ago... this discussion made me realize I had commited in the wrong order so I just fixed ti:
https://github.com/abwillis/voix/blob/master/voix.c

Rich Walsh

  • Sr. Member
  • ****
  • Posts: 331
  • Karma: +23/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: redirect stdout, stderr and stdin
« Reply #4 on: August 10, 2021, 06:18:14 am »
it's when I want to add redirection of stdin that things stop working.

* Is your app writing to the write handle of the stdIn pipe (what I labelled 'writeIn')?

 * If the app you're talking to is line-oriented, are you ending your commands with a CR/LF?

* Is your app writing to stdIn/Out/Err (i.e. handles 0/1/2)? It shouldn't - it should use the dup'd handles in savIn/Out/Err which are all still connected to the console.