how to show a Terminal from LC under OSX?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KurtR
LiveCode Member
LiveCode Member
Posts: 6
Joined: Mon Dec 05, 2011 5:34 pm

how to show a Terminal from LC under OSX?

Post by KurtR » Wed Dec 14, 2011 3:01 am

Hi, total LiveCode beginner here, trying to figure out how to show a Terminal, called from LC. I'm on a mac. The application I am writing must call an external application that shows the status of a connected device (MIDI). The problem is that when I run the LC shell command, I can only get the immediate standard output, then the shell returns. However, there is output over time, so I need to open an external Terminal, so the user can watch the device output.

In other words, my user needs to monitor an external program running in a Terminal session. So how do I load and show an external Terminal session? Nothing I have tried works, including calling 'Terminal.app', using the 'open' command, etc. Is LC suppressing the Terminal app?

KurtR
LiveCode Member
LiveCode Member
Posts: 6
Joined: Mon Dec 05, 2011 5:34 pm

Re: how to show a Terminal from LC under OSX?

Post by KurtR » Wed Dec 14, 2011 5:59 am

addendum:

I just discovered that you can open a terminal with:

launch "/Applications/Utilities/Terminal.app"

However, the launch command does not allow an argument, for Terminal to run. Launch only allows the name of a doc to open, but that does not work as I want to pass in a command to run IN the terminal. So is there another way to run a Terminal that allows arguments, or perhaps a shell that will spawn inside Terminal.app?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4036
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: how to show a Terminal from LC under OSX?

Post by bn » Wed Dec 14, 2011 1:18 pm

Hi Kurt,

look at shell in the dictionary.

Code: Select all

on mouseUp
   set the defaultfolder to specialFolderPath("desktop")
   put shell("ls -l *.*") into field 1
end mouseUp
try this in a button and a field

KInd regards

Bernd

KurtR
LiveCode Member
LiveCode Member
Posts: 6
Joined: Mon Dec 05, 2011 5:34 pm

Re: how to show a Terminal from LC under OSX?

Post by KurtR » Wed Dec 21, 2011 12:30 am

Bernd,
Vielen Dank! That works, however, this terminates too soon. I also need to find a way to run a slow process in the shell, and show the ongoing updates over time. Is there a way to pipe the output of a shell into a LC field, showing updates as they happen?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: how to show a Termin al from LC under OSX?

Post by sturgis » Wed Dec 21, 2011 1:34 am

Look at open process, that way you can start a process and do a read loop to keep updating a status field. If I recall, shell is blocking so if its a long shell execution you're pretty much stuck waiting for it to finish. However, there is a thread here somewhere where Bob S set up an external standalone stack that is used as a progress indicator to make it easier to show an updating busy status. Since its in its own seperate stack with integrated engine, it doesn't get blocked when you do stuff in your real stack. I'm wondering if the reverse could be done.

Set up a stack JUST to do your long term shell and maybe have the shell command output to a file which could be checked by your main stack. (or.. um. something like this, haven't thought it out very well yet, but there might be an option that would achieve your goals by going this direction)

Of course open process is probably sufficient and wouldn't need a middleman file or a separate standalone to do the shells.. So maybe nevermind the second idea!
kurtrowleyGA047f wrote:Bernd,
Vielen Dank! That works, however, this terminates too soon. I also need to find a way to run a slow process in the shell, and show the ongoing updates over time. Is there a way to pipe the output of a shell into a LC field, showing updates as they happen?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: how to show a Terminal from LC under OSX?

Post by mwieder » Wed Dec 21, 2011 1:57 am

Also, if you keep what you've got and add the command

Code: Select all

set the hideconsolewindows to false
your current terminal window will stay on the screen and not disappear when the command is done. Keep in mind, though, that shell is a blocking command, so you won't be able to do anything else until you do exit the terminal window. In that case you'll want to look into the process commands.

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Location: Maryland, USA
Contact:

Re: how to show a Terminal from LC under OSX?

Post by Nonsanity » Wed Mar 07, 2012 5:14 pm

As "open process" has never made it to OS X (does 5.5 have it yet? phu-leeease?) you have to use shell(), but this can be done without blocking.

If you set up your shell command to run in the background ("&") and send the output to a text file ("> /tmp/myoutput.txt") then the shell command will return immediately and you can start polling the text file to monitor the progress. You may also want to poll the process itself with another shell command ("ps") and see if your task is still running and do something when it stops.

I've done this to monitor a Handbrake conversion in order to cue several up and show progress in my stack.

One word of caution... Sometimes the shell command will STILL block on a command that's supposedly been backgrounded. I never figured out exactly why some commands did this and some didn't. It didn't seem to have any obvious logic behind it.

~ Chris Innanen
~ Nonsanity
~ Nonsanity
~ Chris Innanen

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: how to show a Terminal from LC under OSX?

Post by sturgis » Wed Mar 07, 2012 5:24 pm

open process does work for osx. Surely as of 4.5, but I believe before that also. (introduced at 1.0 but the dictionary doesn't give a backtrack of changes so no way to tell what support was added when)

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Location: Maryland, USA
Contact:

Re: how to show a Terminal from LC under OSX?

Post by Nonsanity » Wed Mar 07, 2012 5:43 pm

Let me clarify: The open process command doesn't work on OS X to start command line UNIX processes, like the ones I was talking about.

As per the current docs:
Note: On OS X systems, you can use the open process command to start up an application, but not a Unix process. To work with a Unix process, use the shell func instead.
~ Chris Innanen
~ Nonsanity
~ Nonsanity
~ Chris Innanen

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: how to show a Terminal from LC under OSX?

Post by sturgis » Wed Mar 07, 2012 7:13 pm

DOH. Yep. Sometimes that whole reading thing for me just doesn't work quite right!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”