Xojo Conferences
XDCMay2019MiamiUSA

[MBS] Fwd: execute rb app from a webserver or commandline (MBS Xojo Plugin Mailinglist archive)

Back to the thread list
Previous thread: [MBS] "InterfaceLib-GetComponentResource" could not be found.
Next thread: [MBS] 3.2pr14


Re: [MBS] MIDI Destinations and External Devices   -   Ron Benditt
  [MBS] Fwd: execute rb app from a webserver or commandline   -   Matthias Buercher
   Re: [MBS] Fwd: execute rb app from a webserver or commandline   -   Christian Schmitz
    Re: [MBS] Fwd: execute rb app from a webserver or commandline   -   Matthias Buercher
     Re: [MBS] Fwd: execute rb app from a webserver or commandline   -   Christian Schmitz
   Re: [MBS] Fwd: execute rb app from a webserver or commandline   -   James Sentman
    Re: [MBS] Fwd: execute rb app from a webserver or commandline   -   Matthias Buercher
   [MBS] "InterfaceLib-GetComponentResource" could not be found.   -   Mike D.

[MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 17:11 (Mon, 21 Apr 2003 18:11:49 +0200)
From: Matthias Buercher

>
>>> Can I execute a rb app from an external source- command line or as a
>>> cgi script with passed parameters?
>>
>> On OS X, you can execute it from the command line with the "open"
>> command (just like with any other app or document). That should work
>> for most CGI languages too, assuming proper privileges etc.
>>
>> In OS 9, CGIs are generally written in AppleScript, which can of
>> course launch any app as well.
>>
>> In Win32, you would launch the RB app just like any other executable,
>> by specifying its path on the command line.
>
> the interesting feature would be RB having access to parameters:
> the application class would have the properties: argc as integer and
> argv() as string. actually, argc is even not needed, because we know
> the sizes of the arrays.
> another more logical approach would be to add the argv() as string as
> paramter to the open event.

is there something our wonderboy christian can do about that?

matthias

---------------------------------------------------------
Matthias Buercher <email address removed> www.belle-nuit.com
---------------------------------------------------------
war in iraq - not in my name
http://www.gssa.ch/antiguerre/
http://www.unitedforpeace.org

Re: [MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 17:45 (Mon, 21 Apr 2003 18:45:19 +0200)
From: Christian Schmitz
> is there something our wonderboy christian can do about that?

You mean this question in the FAQ?
<http://www.monkeybreadsoftware.de/realbasic/pluginhelp/faqHowtoreadthec
ommandlin.html>

Mfg
Christian

Re: [MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 23:46 (Tue, 22 Apr 2003 00:46:18 +0200)
From: Matthias Buercher
On Monday, Apr 21, 2003, at 18:45 Europe/Zurich, Christian Schmitz
wrote:

>> is there something our wonderboy christian can do about that?
>
> You mean this question in the FAQ?
> <http://www.monkeybreadsoftware.de/realbasic/pluginhelp/
> faqHowtoreadthec
> ommandlin.html>

i see windows, but what about OS X?

matthias

---------------------------------------------------------
Matthias Buercher <email address removed> www.belle-nuit.com
---------------------------------------------------------
war in iraq - not in my name
http://www.gssa.ch/antiguerre/
http://www.unitedforpeace.org

Re: [MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 23:58 (Tue, 22 Apr 2003 00:58:09 +0200)
From: Christian Schmitz
> On Monday, Apr 21, 2003, at 18:45 Europe/Zurich, Christian Schmitz
> wrote:
>
> i see windows, but what about OS X?

There is no command line for carbon cfm applications as far as I know.

mfg
Christian

Re: [MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 18:19 (Mon, 21 Apr 2003 13:19:48 -0400)
From: James Sentman

On Monday, April 21, 2003, at 12:11 PM, Matthias Buercher wrote:

>
>>
>>>> Can I execute a rb app from an external source- command line or as
>>>> a cgi script with passed parameters?
>>>
>>> On OS X, you can execute it from the command line with the "open"
>>> command (just like with any other app or document). That should
>>> work for most CGI languages too, assuming proper privileges etc.
>>>
>>> In OS 9, CGIs are generally written in AppleScript, which can of
>>> course launch any app as well.
>>>
>>> In Win32, you would launch the RB app just like any other
>>> executable, by specifying its path on the command line.
>>
>> the interesting feature would be RB having access to parameters:
>> the application class would have the properties: argc as integer and
>> argv() as string. actually, argc is even not needed, because we know
>> the sizes of the arrays.
>> another more logical approach would be to add the argv() as string as
>> paramter to the open event.
>>

I have worked extensively on doing this sort of thing and while it may
be possible, it is not "practical" at this particular time. There are
several problems beyond just getting the command line and environment
variables.

An RB app is a carbon app and requires access to the window manager in
order to run, even if it never opens a window or otherwise access the
screen or the menus. This is true even of a command line carbon app, if
you link against carbon you'll call these routines and you can't get
around it. When a program is launched from Apache as a cgi app it is
launched as the apache user which does not have access to the window
manager. Any carbon and most cocoa apps that you run as a cgi will
crash immediately. This includes command line apps like OSACompile or
the other command line apps for manipulating applescripts.

One potential solution to this is to seduid the program to run as root.
Except that this doesn't work for carbon apps. A cfm carbon app like RB
generates isn't really running when you run it, it's being called from
the "LaunchCFMApp" program, so setuid'ing the RB app does nothing.
Indeed you can't even use the C calls to setuid, they don't appear to
do anything. Then there is all the discussion that you'll generate
about security issues of providing a setuid to root program accessible
from the web server.

Doing a SetUID on a little command line C program does work however.
That is basically what I have done to create the ACGI Dispatcher
program on my website. I've got an update to that in the works that
speeds it up by an order of magnitude, but I have several other things
in the pipeline that I have to get done before I can finish debugging
that.

If RB ever switches to doing a MACH-O binary, then you may be able to
setuid from it and run it as a CGI. But even so a regular RB app does a
LOT of extra work in the initialization than you would need from a
command line app and will always take longer to launch/process/quit
than something like an ACGI program. Then there is the problem of
multiple instances of the same app, generally MacOS doesn't let you do
this, if you try to launch an app that is already running you just
activate the current one rather than get another process, so there
would be potential problems with multiple hits being processed at the
same time. There was talk not too long ago about a future version of RB
being able to create command line apps, this may also offer some
workarounds or solutions, but for now we're kind of sunk except using a
separate app to do the dispatching of events.

So, as you can see there are some barriers to entry in the CGI front ;)

Thanks,
James

James Sentman http://www.sentman.com

Re: [MBS] Fwd: execute rb app from a webserver or commandline
Date: 21.04.03 23:55 (Tue, 22 Apr 2003 00:55:27 +0200)
From: Matthias Buercher
> I have worked extensively on doing this sort of thing and while it may
> be possible, it is not "practical" at this particular time. There are
> several problems beyond just getting the command line and environment
> variables.

james,
thank you for the explanation.
actually, i didn't think this for a CGI-application but for a
plugin-style environment or for automation, so that an application can
be called to do some task, with parameters. i see the speed overhead
for initialization.
actually, the best workaround now using it from the commandline would
be to write a binary file with the parameters, set the maccreator to
the application and launch the binary file.
or, maybe easier, just write a small text file and use the -a parameter
of the open command to define the application specifically.

open -a /Applications/TextEdit.app /Volumes/Macintosh HD/foo.txt

it is then the application to detect if the file contains parameters or
is one of the files it is supposed to open.

matthias

---------------------------------------------------------
Matthias Buercher <email address removed> www.belle-nuit.com
---------------------------------------------------------
war in iraq - not in my name
http://www.gssa.ch/antiguerre/
http://www.unitedforpeace.org