Ptty Synchronization

I have a bunch of shell commands I’d like to issue to a Ptty to allow
the user to monitor progress.

The problem I’m having is keeping things sequential and in sync. It
seems that the 2’nd command is executed, but the first is not.

As a test, I am using the following sequence:

o Create a Ptty in PhAB

o Open a Psuedo tty on the Ptty in my app
PtSetArg(&arg, Pt_ARG_TTY_PSUEDO, NULL, 0)
PtSetResources(…)

o Check for success:
PtSetArt(&arg, Pt_ARG_TTY_FD, 0, 0)
PtSetResources(…)
Test arg.value for 1= -1

o Attach my shell via Pt_Arg_TTY_ARGV
o Get the pid of my shell via Pt_ARG_TTY+PID
(may not need it, but I tried wait_pid() to no avail…)

o Issue my shell commands:
PtSetArg(&arg, Pt_ARG_TTY_CMD, “date”, 0);
PtSetResources(…)

PtSetArg(&arg, Pt_ARG_TTY_CMD, “ls”, 0);
PtSetResources(…)

The output for the ‘date’ command never appears, but the ‘ls’ output
does.

If I add a wait_pid() between them, the app just hangs forever with NO
output on the Ptty…

If I issue the ‘date’ command two times in a row, it works!!!, but not
if I change commands…

I got to be missing something fundamental here…

TIA,
Ray L.

PING!!!
Anybody monitoring this group?

Thx…

On Thu, 12 Jul 2001 18:07:16 GMT, Ray.LaBrecque@gretagimaging.com (Ray
LaBrecque) wrote:

I have a bunch of shell commands I’d like to issue to a Ptty to allow
the user to monitor progress.

The problem I’m having is keeping things sequential and in sync. It
seems that the 2’nd command is executed, but the first is not.

As a test, I am using the following sequence:

o Create a Ptty in PhAB

o Open a Psuedo tty on the Ptty in my app
PtSetArg(&arg, Pt_ARG_TTY_PSUEDO, NULL, 0)
PtSetResources(…)

o Check for success:
PtSetArt(&arg, Pt_ARG_TTY_FD, 0, 0)
PtSetResources(…)
Test arg.value for 1= -1

o Attach my shell via Pt_Arg_TTY_ARGV
o Get the pid of my shell via Pt_ARG_TTY+PID
(may not need it, but I tried wait_pid() to no avail…)

o Issue my shell commands:
PtSetArg(&arg, Pt_ARG_TTY_CMD, “date”, 0);
PtSetResources(…)

PtSetArg(&arg, Pt_ARG_TTY_CMD, “ls”, 0);
PtSetResources(…)

The output for the ‘date’ command never appears, but the ‘ls’ output
does.

If I add a wait_pid() between them, the app just hangs forever with NO
output on the Ptty…

If I issue the ‘date’ command two times in a row, it works!!!, but not
if I change commands…

I got to be missing something fundamental here…

TIA,
Ray L.

Hi Ray,

I have spoken to one of the developers and he suggests the following:

Your mistake is to set both Pt_ARG_TTY_ARGV and Pt_ARG_TTY_CMD. They are
just two ways of specifying a new command to start on the PtTty. If you
start a new command before the old one has finished, PtTty attempts to
kill the old one by sending it a signal. That’s probably why your only
seeing the output from the last one: your killing the other ones before
they get a chance to produce any output.

Also, you shouldn’t be calling waitpid() (I assume that’s what you mean
by wait_pid()). The library does that for you. If e wants to know
when the command has finished, you should use the Pt_CB_TTY_TERMINATED
callback.

Hope this helps
Regards
Brenda

Ray LaBrecque <Ray.LaBrecque@gretagimagingnospam.com> wrote:

PING!!!
Anybody monitoring this group?

Thx…

On Thu, 12 Jul 2001 18:07:16 GMT, > Ray.LaBrecque@gretagimaging.com > (Ray
LaBrecque) wrote:

I have a bunch of shell commands I’d like to issue to a Ptty to allow
the user to monitor progress.

The problem I’m having is keeping things sequential and in sync. It
seems that the 2’nd command is executed, but the first is not.

As a test, I am using the following sequence:

o Create a Ptty in PhAB

o Open a Psuedo tty on the Ptty in my app
PtSetArg(&arg, Pt_ARG_TTY_PSUEDO, NULL, 0)
PtSetResources(…)

o Check for success:
PtSetArt(&arg, Pt_ARG_TTY_FD, 0, 0)
PtSetResources(…)
Test arg.value for 1= -1

o Attach my shell via Pt_Arg_TTY_ARGV
o Get the pid of my shell via Pt_ARG_TTY+PID
(may not need it, but I tried wait_pid() to no avail…)

o Issue my shell commands:
PtSetArg(&arg, Pt_ARG_TTY_CMD, “date”, 0);
PtSetResources(…)

PtSetArg(&arg, Pt_ARG_TTY_CMD, “ls”, 0);
PtSetResources(…)

The output for the ‘date’ command never appears, but the ‘ls’ output
does.

If I add a wait_pid() between them, the app just hangs forever with NO
output on the Ptty…

If I issue the ‘date’ command two times in a row, it works!!!, but not
if I change commands…

I got to be missing something fundamental here…

TIA,
Ray L.

On 13 Jul 2001 14:31:58 GMT, Gui Group <gui@qnx.com> wrote:

Hi Ray,

I have spoken to one of the developers and he suggests the following:

Your mistake is to set both Pt_ARG_TTY_ARGV and Pt_ARG_TTY_CMD. They are
just two ways of specifying a new command to start on the PtTty. If you

Two things:
1: this code was copied directly form your knowledge base
2: I only used TTY_ARGV to start the shell when the PTerm is opened,
used TTY_CMD after that. Sorry for the confusion. (probably should
have pasted in the exact code instead of saving space by outlining my
effort…)

start a new command before the old one has finished, PtTty attempts to
kill the old one by sending it a signal. That’s probably why your only
seeing the output from the last one: your killing the other ones before
they get a chance to produce any output.

Based on the action I saw, this make sense. Too bad the ‘commands’
aren’t queued up…

Also, you shouldn’t be calling waitpid() (I assume that’s what you mean
by wait_pid()). The library does that for you. If e wants to know
when the command has finished, you should use the Pt_CB_TTY_TERMINATED
callback.

Ok, results:
o I eliminated all waitpid() related code
o Added a flag to denote that the Ptty was busy;
o Now loop on PtProcessEvent() while busy flag is set.

All is well.

Thank you VERY much.
The direct and accurate response is greatly appreciated.

Ray L.

Hope this helps
Regards
Brenda

Ray LaBrecque <> Ray.LaBrecque@gretagimagingnospam.com> > wrote:
PING!!!
Anybody monitoring this group?

Thx…

On Thu, 12 Jul 2001 18:07:16 GMT, > Ray.LaBrecque@gretagimaging.com > (Ray
LaBrecque) wrote:

I have a bunch of shell commands I’d like to issue to a Ptty to allow
the user to monitor progress.

The problem I’m having is keeping things sequential and in sync. It
seems that the 2’nd command is executed, but the first is not.

As a test, I am using the following sequence:

o Create a Ptty in PhAB

o Open a Psuedo tty on the Ptty in my app
PtSetArg(&arg, Pt_ARG_TTY_PSUEDO, NULL, 0)
PtSetResources(…)

o Check for success:
PtSetArt(&arg, Pt_ARG_TTY_FD, 0, 0)
PtSetResources(…)
Test arg.value for 1= -1

o Attach my shell via Pt_Arg_TTY_ARGV
o Get the pid of my shell via Pt_ARG_TTY+PID
(may not need it, but I tried wait_pid() to no avail…)

o Issue my shell commands:
PtSetArg(&arg, Pt_ARG_TTY_CMD, “date”, 0);
PtSetResources(…)

PtSetArg(&arg, Pt_ARG_TTY_CMD, “ls”, 0);
PtSetResources(…)

The output for the ‘date’ command never appears, but the ‘ls’ output
does.

If I add a wait_pid() between them, the app just hangs forever with NO
output on the Ptty…

If I issue the ‘date’ command two times in a row, it works!!!, but not
if I change commands…

I got to be missing something fundamental here…

TIA,
Ray L.