Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > RealBasic Newbie struggling with shell and threading

RealBasic Newbie struggling with shell and threading
Thread Tools
Junior Member
Join Date: Jun 2001
Location: Houghton Regis, UK
Status: Offline
Reply With Quote
Sep 2, 2001, 08:19 PM
 
OK, I've been through the tutorial and language reference. I've done a _lot_ of experimenting. Now I'm pulling hair.

I'm writing an app with RB 3.2.1 that uses shell to fire off a nice long shell command. The command in question (without giving everything away) can output its progress to a logfile continuously. I want to use this to give progress feedback to the user via a progress bar or even a live update of the contents of the file. I can fire off the command in one thread and monitor the logfile in another but the textfield or progress bar won't update until the threads finish. This makes me wonder what I gain by threading in the first place! I can get an update in the text window telling me that the threads have started and that they've finished. However, if I embed in my loop that monitors the logfile commands to update the progress bar or text field then none of these updates appear until the thread is done. Obviously this behaviour is useless to me. I'm sure RB wouldn't include progress bars unless one could use them so what am I missing?
----
Sam Agnew
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 4, 2001, 12:55 PM
 
I think you'lll probably find the issue here is that RB's shell class sucks. You are welcome to use progressbars from threads, in fact I seem to remember one of the programs in REALbasic: The Definitive Guide is a "progressbar race", which uses a thread. I don't think that RB's shell class will allow you to get partial output from commands. I could, of course, be wrong, but I don't think that I am. A much better solution would be to not bother with REALbasic, Cocoa is *much* nicer, less bloated, doesn't have any of the UI issues under OS X that RB does, and just all round sucks less.
     
Forum Regular
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 4, 2001, 01:16 PM
 
but cocoa may be too difficult for newbies. buy the learing cocoa book then buy the realbasic book.

decide for yourself what your skill level is and move forward on that.
     
Fresh-Faced Recruit
Join Date: Jul 2001
Location: Germany
Status: Offline
Reply With Quote
Sep 10, 2001, 04:08 AM
 
The RB shell is a rough implementaiotn of the C popen() function.
The shell will only return a value after it has finished.
So you have to split your command into smaller parts to set the value of your progress bar after each.
Or wait for OS X 10.1, then you can use AppleScript to control Terminal.app, which should eliminate a lot of your problems.

Holger
     
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Sep 10, 2001, 05:38 AM
 
Originally posted by Angus_D:
<STRONG>I think you'lll probably find the issue here is that RB's shell class sucks. You are welcome to use progressbars from threads, in fact I seem to remember one of the programs in REALbasic: The Definitive Guide is a "progressbar race", which uses a thread. I don't think that RB's shell class will allow you to get partial output from commands. I could, of course, be wrong, but I don't think that I am. A much better solution would be to not bother with REALbasic, Cocoa is *much* nicer, less bloated, doesn't have any of the UI issues under OS X that RB does, and just all round sucks less.</STRONG>
Please stop trolling about REALbasic, he was asking for a solution to his problem in REALbasic and NOT Cocoa. I bet that when he has a question about Cocoa, he will ask you oh great Cocoa fellows.

About the thread and shell thing, I think it is nearly impossible with the atcual state of the RB shell class to get the progress of the command status. Maybe there is a workaround, but it is not easy for sure.

BTW, Cocoa do not have a NSShell class or something similar, and the NSTask thing is buggy enough to keep any developer busy trying to get the damned utility working and getting the output correctly. The shell class of RB may suck, but it is easy to get it to actually work.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 10, 2001, 03:29 PM
 
Originally posted by eevyl:
<STRONG>Please stop trolling about REALbasic, he was asking for a solution to his problem in REALbasic and NOT Cocoa. I bet that when he has a question about Cocoa, he will ask you oh great Cocoa fellows.</STRONG>
I also replied to his question, and merely pointed out that it was a limitation of RB, and some other things that make Cocoa more preferable to RB.

<STRONG>About the thread and shell thing, I think it is nearly impossible with the atcual state of the RB shell class to get the progress of the command status. Maybe there is a workaround, but it is not easy for sure.</STRONG>
Yes, that's what I said.

<STRONG>BTW, Cocoa do not have a NSShell class or something similar, and the NSTask thing is buggy enough to keep any developer busy trying to get the damned utility working and getting the output correctly. The shell class of RB may suck, but it is easy to get it to actually work.</STRONG>
NSShell? what? NSTask works for executing commands. I don't see what would be the point in an NSShell class? What would it do? NSTask isn't buggy, it works fine from my experience. Getting the output is very easy too. And you can use the NSFileHandle's -readInBackgroundAndNotify to get the output incrementally, and you can also pipe from one command to another, etc etc. And, if you ask me, NSTask is just as easy to use as RB's shell class. Something like:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> NSTask *myTask = [[NSTask alloc] init];
[myTask setPath:<font color = orange>@"/path/to/executable"</font>];
[myTask run];
[myTask release];
(<font color = green>this</font> could be simplified using a convenience constructor, granted)</font>[/code]

compared to:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> dim s as shell
s = new shell
s.execute /path/to/executable</font>[/code]

I think that the syntax is probably wrong, but it basically shows that they are almost exactly the same complexity. And the NSTask implementation is just fundamentally better.
     
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Sep 10, 2001, 04:06 PM
 
Originally posted by Angus_D:
<STRONG>
&lt;blockquote&gt;&lt;font size=1 face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;hr&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt; NSTask *myTask = [[NSTask alloc] init];
[myTask setPath:&lt;font color=orange&gt;@"/path/to/executable"&lt;/font&gt;];
[myTask run];
[myTask release];
(&lt;font color=green&gt;this&lt;/font&gt; could be simplified using a convenience constructor, granted)&lt;/font&gt;&lt;/pre&gt;&lt;hr&gt;&lt;/blockquote&gt;

compared to:

&lt;blockquote&gt;&lt;font size=1 face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;hr&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt; dim s as shell
s = new shell
s.execute /path/to/executable&lt;/font&gt;&lt;/pre&gt;&lt;hr&gt;&lt;/blockquote&gt;
</STRONG>
And what about this:

&lt;blockquote&gt;&lt;font size=1 face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;hr&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt; dim s as shell
s = new shell
s.execute /path/to/executable
msgbox s.result&lt;/font&gt;&lt;/pre&gt;&lt;hr&gt;&lt;/blockquote&gt;

Is there an easy way of obtaining the result text of a command line utility in Cocoa? Probably, but it is easier in RB.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:54 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2