Text List to String

Hello.

I am a bit hair sore about the second comment. But if you put it that way. But still I want to say, that I produce stuff, when I have good ideas, (in my own mind), and I test it, as duly, as I think proper, when I write it. But, occasionally, it do happen that I haven’t thought of everything, when I post it. And if people then discover a bug, then they are welcome to say that, and I’ll fix it, but some staged/planned testing of everything, that is not going to happen, there is no room for that. The alternative is to not post here. I am careful to make stuff work under the conditions I see, as good as possible. But sometimes, I have to stop somewhere, with a quality I can live with (SafariSearchTabs). If someone then want something more, they are welcome to either fix it themselves, and share the result, or send me money! :slight_smile:

As for the first one, you really create a pty device, by using some pty mechanism, you can read about in Advanced Unix Programming, the reason for doing so, is to give programs that run in shells, the impression that they still are having, at least an equivalent to a tty. It is like setting up a primitive server, so you can get at the input and output of the streams. (It works the same way as the program you use for recording input output of a shell in a terminal window.

Try ls /dev/pty/*
The article at Wikipedia aren’t that good in this case.

I have actually programmed a pseudo terminal, and to me, using a pseudo terminal is to emulate a terminal device through files. I’ll keep you informed if I upload the code to github.

:|I’m sorry about that. Please read it in context, I first implies that AppleScript is some kind of second hand language, the last sentence is correcting that point. The word ‘you’ could be better written down as ‘it’ because it means in general not to you me or anyone in specific.

I don’t really understand your answer about tty and do shell script but I also found something else out. Try the tty command in terminal and in do shell script. In do shell script it will return an error saying that there is no tty. Also to run an input output wrapper around an shell like tty or pty the shell needs to be invoked as interactive. Do shell script are shell that are non-interactive.

That is the whole idea behind the pty you fake the context of a terminal device for the utilities that are executed through a system-like call, there is still fork/exec in the bottom of it. But the utilites may think that they are executed the regular way, and you get the output like you had dup’ed a stream, (the utility thinks it justs sends it to stdout, the same with stdin, that is the way you send think in, no much different than a pipe() call, but different enough, so that the utilitiy thinks it is working from a terminal, which is sometimes necessary to make stuff just work.

I sent you the pty-link in the previous post, youo just don’t use pty for arranging a physical terminal, but I think the login process uses pty for doing just that, but then it hands it over to a real terminal.

This might seem like an unecessary step, but some programs, expects linebuffered input from /dev/tty, and other redirect output to /dev/tty, or write directly, you would use pty for setting it up, so you can intercept it, see the graph on the wikipedia page, that I linked in, in my previous post.

And this is the way I believe the do shell script works, and I’m still sure that I have read that somewhere.

You can also take a look at the source of this simple script command You’ll see that the paren’t process designates it self as master, and the subshell as the slave, that gets input it believes comes from stdin, and delivers, to what it thinks is stdout, without never really being in contact with a terminal.

I know what pty does and tty and the differences between them. I meant that I didn’t understand your reply against my post. Are we talking about terminal.app or do shell script? Because there is no pty nor tty used by do shell script it was confusing to me to which you relate. I assume it was an general post about pty and tty and not really in response to my answer to your question.

Hello.

What I meant that I believe, is that do shell script uses a pty construct, to “hijack” stdin and stdout, when it performs the system calls, in order to intercept stdin, stdout, and stderr. (So the executed shell-utilites behaves as they normally would do, with linebuffering (awk), and what else they need to perform properly.

The way a pty program works, fits beautifully by the way you can send a job to the background with stderr and stdin redirected to /dev/null when you use do shell script by the way. Because then the pty-layer will just return immediately, after having instigated the “job”.

I am not sure (totally) if there are pty’s involved when executing a do shell script, but I find it very natural if there were, as that would have been the easiest way to make the do shell script command work.

Nice blog. :slight_smile:

Edit

I know, a terminal session is also called a pseudo terminal, but if you use the ps command, you’ll see /dev/tty, and you can use ttyname or just tty, to get the tty name.

The ptty’s I am talking about, doesn’t give a /dev/tty back, they won’t work with tty or pty name, but you should be able to find a /dev/pty somewhere.

Well, having written this, I fired up lsof to see, and I didn’t find any pty’s, I did however find either streams, or unix sockets. The streams might be more like System V streams (and there they work with pty’s :slight_smile: ). So this question is really open. The technique for implementing a do shell script, should however be much the same way as you would install a pty as layer between shell commands, and the program invoking it, like telnet, rlogin, ssh, session and tpmux. (In principle).

Hi guys.

Would you mind taking this discussion somewhere else? It’s way off-topic for the thread.

Consider it done