From: Robert Klemme Date: 2007-12-24T04:49:59+09:00 Subject: Re: Fairly elementary UNIX question On 23.12.2007 19:57, Ken Bloom wrote: > Steckly, Ron wrote: >> I've been learning a lot about the .NET architecture and scripting to it >> using Visual Basic and C#. I'm trying to write a program right now in >> UNIX and I'm a little perplexed. How do I tap into events in UNIX? For >> example, if I were to write a script to enter a command into the R >> Statistics Program running in Linux, how would I do that? >> >> Normally, in bash I would type R >> >> And a new prompt comes up and you can type whatever command you want. >> >> I'd like to be able to make a simple GUi for it so that its easier for >> people to enter commands who are still learning R. But I'm not sure how >> to script to a terminal.... >> >> Am I completely on the wrong track? > > On UNIX, terminal programs simply have a few open pipes (which behave > like files) by default, the standard input, standard output, and > standard error. When you start a new program, the calling program is > given the other end of each of those pipes. (It's a little more > complicated, but various ruby libraries abstract away the compliation > and make this process appear exactly as I said it.) When a program > runs in a terminal on UNIX, the terminal is the calling process. All > the terinal does is display the data that's written to stdout and > stderr, and takes keyboard input and sends it to stdin. When > Ruby calls a program, Ruby is the calling process, and you can use the > pipes however you want. You can get access to the pipes by using popen > (built-in) or the Open3 or Open4 libraries. > > Note that if you want the output of R to appear on Ruby's calling > terminal, you have to do a little work to put the output there > yourself. Sorry to nitpick, but if you start a program from the shell without a pipeline and any redirections , stdout, stderr and stdin are not connected to pipes but to devices of the terminal. (This is also true for the shell's own file descriptors 0, 1 and 2.) Kind regards robert