Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
9001 posts
|
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. _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
7 posts
|
Hi Mariano,
to access the arguments from inside topaz you can use a feature of most unix shells called "here document". This concept allows you to embed a document inside your shell script which gets passed to stdin of any executable: executable <<LimitString firstCommand nextCommand $1 LimitString The document is surrounded by any given string. The shell itself will substitute the environment variables and replace them by there values before the document is passed to the executable. So use something like the following: #!/bin/bash
if [ -z \$1 ];
then
echo "argument expected"
fi
input $MYAPP_CONFIG/mylogin.topaztopaz -l <<EOF set gems $STONENAME user Username pass TopSecret login printIt '$1' printString % exit EOF You used "run" inside your script which is a normal "do-it". I replaced it by "printIt" because I assume that you are interessted in the evaluated expression. Topaz has a directive called input. Use that to load other code or if you don't like the login credentials hardcoded in the script: Hope that helps. Br, Ralph Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
... [show rest of quote]
_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
9001 posts
|
On Tue, Jan 14, 2014 at 4:27 AM, Ralph Mauersberger <[hidden email]> wrote:
Hi Ralph, thanks for the explanation. So indeed, it seems that is what is being used by startSeaside30_adaptor which does:
cat << EOF | nohup $GEMSTONE/bin/topaz -l -e $4 2>&1 >> $GEMSTONE_LOGDIR/${1}_server-${2}.log &
... [show rest of quote] OK, that worked and gets what I want. But....I am unable to apply the same "Here Document" approach to my real needs:
cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" Notice that $1 is the topaz script I send as an argument (yes, it can have a EOF at the end). Also, I am executing topaz with a "su -m -c ..." so that changes the things I guess.
Do you know how can I adapt the above line to use the Here Document features? I would like to access the arguments inside the topaz script sent as argument ($1 in this case).
yes, thanks :)
mmm good idea. So...to conclude: /opt/gemstone/product/bin/topaz -ql -T200000 <<EOF login
printIt '$1' printString % exit EOF that works. But if I do exactly the same but in the file passed as argument, it does not work anymore:
/opt/gemstone/product/bin/topaz -ql -T200000 <<EOF input $1 EOF Any ideas? Thank!
... [show rest of quote] Mariano http://marianopeck.wordpress.com _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
7 posts
|
... [show rest of quote]
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. 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 The here document is just to make the example complete. This way you can access the env vars from within any method. Br, Ralph
... [show rest of quote]
_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
9001 posts
|
... [show rest of quote] 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?
Ok, (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG' does answer correctly. weird...
Thanks!!
... [show rest of quote] Mariano http://marianopeck.wordpress.com _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
9001 posts
|
On Tue, Jan 14, 2014 at 1:01 PM, Mariano Martinez Peck <[hidden email]> wrote:
... [show rest of quote] I forgot to said....somehow that works for startSeaside30_Adaptor.... but I don't understand how it can do it.
... [show rest of quote] Mariano http://marianopeck.wordpress.com _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
7 posts
|
Mariano Martinez Peck schrieb:
... [show rest of quote]
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.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.
... [show rest of quote]
_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
9001 posts
|
On Tue, Jan 14, 2014 at 1:43 PM, Ralph Mauersberger <[hidden email]> wrote:
... [show rest of quote] 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?
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.
... [show rest of quote] Mariano http://marianopeck.wordpress.com _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
946 posts
|
In reply to this post by Mariano Martinez Peck
I have created a bug related to this, to allow Smalltalk to access the command line arguments (i.e., argv) that were used to launch the Gem.
43659: 'Add the ability to get the command arguments used to launch the gem' This means that the Topaz session will have access to them, but only within the Smalltalk portion of the system. Since that's where we all want to play anyway, it should be good. :-) It looks like it will make it into 3.2. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
7 posts
|
In reply to this post by Mariano Martinez Peck
... [show rest of quote]
Hmm, really strange. I have no idea. The example above works as
expected for me. I tested on a non-GLASS GemStone/S 64 2.4.4.7 (SPARC
Solaris). So maybe a bug in a recent GS 3.x or whatever version you are
using?_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Free forum by Nabble | Edit this page |