ThePrez / ServiceCommander-IBMi

Service Commander for IBM i
Apache License 2.0
40 stars 12 forks source link

[BUG] STRTCPSVR doesn't show `sc` output in 5250 #117

Closed ThePrez closed 2 years ago

ThePrez commented 2 years ago

See #115/#116 for some context, but the reason the STRTCPSVR handler sometimes runs in non-batch mode is because during bringup, I was able to see sc progress messages, warnings, etc.

Even outside the scope of STRTCPSVR, I can't get this desired behavior. For instance, if I run:


CALL PGM(QP2SHELL ) PARM('/QOpenSys/pkgs/bin/bash' '-l' '-c'            
        'echo hi && exec /QOpenSys/pkgs/bin/sc start zookeeper 2>&1 |cat
;echo done  ;sleep 5'                  )                                
``
... the "hi" and "done" show on the screen but the `sc` output does not!! 😠 
cc @chrjorgensen for awareness/input
chrjorgensen commented 2 years ago

Why the 'cat' command?

chrjorgensen commented 2 years ago

If you remove the "|cat" part it works...!

chrjorgensen commented 2 years ago
CALL PGM(QP2SHELL)                                          
     PARM('/QOpenSys/pkgs/bin/bash' '-l' '-c' 'echo hi && echo hi again 2>&1; echo done; sleep 5')           

gives the following output:

hi                                  
hi again                            
done                                
Press ENTER to end terminal session.
ThePrez commented 2 years ago

@chrjorgensen , the |cat made this mysteriously work during bringup (should have documented that!).

Your sample QP2SHELL invocation works for me also, but if I put the /QOpenSys/pkgs/bin/sc command in there, the sc output still goes to SPLF (at least on my current system).

I'm very confused. Is it something different with how bash is handling subshells? Something to do with blended stderr/stdout? Something particular on my system?

ThePrez commented 2 years ago

This is the only real change I ever made to the sc script.. https://github.com/ThePrez/ServiceCommander-IBMi/commit/08e5ccc0dfc1c41cc11b8519589dc4ab744eea8e

chrjorgensen commented 2 years ago

According to this link about QP2SHELL it does not reliably setup stdin, stdout and stderr - and it is suggested to use QSH instead.

What do you think about this? My test using QSH instead of QP2SHELL (after changing some quotes) worked and the output from the sc command was returned to my 5250 job...

ThePrez commented 2 years ago

I seem to recall that QP2SHELL won't set up the descriptors, but bash would. Maybe it's a matter of reliably setting up descriptors Did you need to set QIBM_MULTI_THREADED for it to work? Or can you do that right on the QSH invocation? If memory serves me right, I shied away from QSH on the first impl because:

I think all of those are horrible reasons, so it's worth a revisit

chrjorgensen commented 2 years ago

I see two options:

stdin, stdout, and stderr must be forkable file descriptors

(mentioned in the link).

I have always been confused about QP2SHELL - probably for the same reasons that is causing these problems with stdout back to the job.

kadler commented 2 years ago

You can open file descriptors in Bourne shells if you want: https://bash.cyberciti.biz/guide/Opening_the_file_descriptors_for_reading_and_writing

That works for standard files, but won't get you the "fake" stdin/stdout/stderr provided by QSH/QP2TERM.

kadler commented 2 years ago

I don't believe that bash will set up file descriptors. Those are supposed to be set up by the caller.