[Glass] run topaz from bash and have access to arguments from topaz smalltalk
Mariano Martinez Peck
marianopeck at gmail.com
Tue Jan 14 09:49:49 PST 2014
On Tue, Jan 14, 2014 at 1:43 PM, Ralph Mauersberger <
ralph.mauersberger at ewetel.de> wrote:
> Mariano Martinez Peck schrieb:
>
>
>
>
> On Tue, Jan 14, 2014 at 1:01 PM, Mariano Martinez Peck <
> marianopeck at gmail.com> wrote:
>
>>
>>>
>>> Mariano,
>>>
>>> that should be correct and it works for me. I tested with the following
>>> two scripts:
>>>
>>> test.sh with the following lines:
>>>
>>> #!/bin/bash
>>> topaz -ql <<EOF
>>> input $1
>>> EOF
>>>
>>>
>>> and input.topaz like this:
>>>
>>> set gems seaside user DataCurator pass swordfish
>>> login
>>> printIt
>>> 20 factorial
>>> %
>>>
>>> I can execute "bash test.sh input.topaz" and get the result.
>>>
>>>
>> OK, that works for me. But...is there a way I can for example, get
>> something like this: I would like to access the parameters from input.topaz
>> script. For example:
>>
>> set gems seaside user DataCurator pass swordfish
>> login
>> printIt
>> $2 factorial
>> %
>>
>> And then call it like this:
>>
>> "bash test.sh input.topaz 20"
>>
>> I would like to do that without having to export each variable
>> individually... maybe using $@ somewhere?
>>
>>
> Hmm, I don't think that there is a way to get something like that
> directly working. Of course there are workarounds, like storing $2 to a
> file, save it to sessionState or whatever and afterwards access it from
> within input.topaz with appropriate smalltalk code.
>
>
OK.... I got it. But just to confirm... this works:
#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System performOnServer: 'echo $MYARG').
%
login
printIt
'$1' printString
%
exit
EOF
and run it "sh runTopaz.sh mariano"
but if we move the topaz script to a separate file and we do the input...it
doesn't work anymore:
#!/bin/bash
export MYARG=$1
topaz -l <<EOF
input test.tpz
EOF
"sh runTopaz.sh mariano"
and test.tpz being:
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System performOnServer: 'echo $MYARG').
%
login
printIt
'$1' printString
%
exit
so the only way to get it work is to embed the topaz script inside the bash
script right? (like the first example)
Ok...if I embed the topaz script in the bash (not using input) I can access
both, parameters and exported variables, from both, topaz and smalltalk.
If I don't embed the topaz script (use input), then, I cannot access any
variable either from topaz or smalltalk.
so...this is the expected behavior right?
> I forgot to said....somehow that works for startSeaside30_Adaptor....
> but I don't understand how it can do it.
>
> Maybe I'm blind, but I can't see any special trick in
> startSeaside30_Adaptor. It's just one here document passed to "cat", the
> result is piped to topaz. $1 and $2 are used inside the here document and
> are substituted by the shell like we discussed it. $1 and $2 are also used
> to specify the log file name.
>
>
You right, I missed that difference. You right, it's not the same case.
Thanks a lot Ralph for your help, it is really appreciated.
>
>
>
>
>>
>>
>>> Just as addition and independent of the here documents approach: Another
>>> way to access the shell script arguments would be to export them to the
>>> environment and access them via System>>gemEnvironmentVariable:. So the
>>> following should also work:
>>>
>>> #!/bin/bash
>>> export MYARG=$1
>>> topaz -l <<EOF
>>> set gems seaside user DataCurator pass swordfish
>>> login
>>> printIt
>>> 'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
>>> %
>>> exit
>>> EOF
>>>
>>>
>> Ok, (System gemEnvironmentVariable: 'MYARG') is answering nil ...
>> however.....System performOnServer: 'echo $MYARG' does answer correctly.
>> weird...
>>
>>
>>
>>> The here document is just to make the example complete. This way you can
>>> access the env vars from within any method.
>>>
>>>
>> Thanks!!
>>
>>
>>
>>> Br,
>>> Ralph
>>>
>>>
>>>
>>> Any ideas?
>>>
>>> Thank!
>>>
>>>
>>>
>>>
>>>
>>> Hope that helps.
>>>>
>>>> Br,
>>>> Ralph
>>>>
>>>>
>>>>
>>>> Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
>>>>
>>>> Hi guys,
>>>>
>>>> In Norbert's utilize, we have this nice script runTopazScript.sh :
>>>>
>>>> #!/bin/sh
>>>>
>>>> source $APPLICATION_DIR/env
>>>>
>>>> if [ -z \$1 ];
>>>> then
>>>> echo "no script name given"
>>>> fi
>>>>
>>>> cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c
>>>> \"$GEMSTONE/bin/topaz -ql -T200000 \"
>>>>
>>>>
>>>> That let us automatically connect to GemStone using an auto-generated
>>>> .topazini. So we can pass around a topaz script and that would be execute.
>>>> So we can do for example:
>>>>
>>>> sudo sh ./runTopazScript.sh something.tpz
>>>>
>>>> Now....I saw in several topaz scripts from seaside that the SMALLTALK
>>>> code is able to directly access the argument variables to the shell. For
>>>> example, startSeaside30_adaptor does:
>>>>
>>>> GsFile gciLogServer: '$1 Server started on port ', $2 printString.
>>>>
>>>> I want to do the same in my something.tpz. Imagine I have this
>>>> something.tpz file:
>>>>
>>>> run
>>>> $1 printString.
>>>> %
>>>>
>>>> And I execute:
>>>>
>>>> sudo sh ./runTopazScript.sh something.tpz mariano
>>>>
>>>> So how can we adapt the script so that such a smalltalk script
>>>> outputs 'mariano' instead of the literal string $1 ?
>>>>
>>>> I tried adding a & at the end of the topaz call and many other
>>>> workarounds but I am not sure if topaz needs something special for this.
>>>>
>>>>
>>>> Thanks a lot in advance and sorry for the offtopic.
>>>>
>>>> --
>>>> Mariano
>>>> http://marianopeck.wordpress.com
>>>>
>>>>
>>>> _______________________________________________
>>>> Glass mailing listGlass at lists.gemtalksystems.comhttp://lists.gemtalksystems.com/mailman/listinfo/glass
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Glass mailing list
>>>> Glass at lists.gemtalksystems.com
>>>> http://lists.gemtalksystems.com/mailman/listinfo/glass
>>>>
>>>>
>>>
>>>
>>> --
>>> Mariano
>>> http://marianopeck.wordpress.com
>>>
>>>
>>>
>>> _______________________________________________
>>> Glass mailing list
>>> Glass at lists.gemtalksystems.com
>>> http://lists.gemtalksystems.com/mailman/listinfo/glass
>>>
>>>
>>
>>
>> --
>> Mariano
>> http://marianopeck.wordpress.com
>>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
>
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>
>
--
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140114/d7ac1bf8/attachment.html>
More information about the Glass
mailing list