Re: About passing args to Jython

Jeff Allen <[email protected]> Thu, 27 Jun 2019 08:36:12 +0100
Newsgroups gmane.comp.lang.jython.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============7500847036013258702==
Content-Type: multipart/alternative;
 boundary="------------A40B959ED238F3C841660711"
Content-Language: en-GB

This is a multi-part message in MIME format.
--------------A40B959ED238F3C841660711
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Евгений:

sys.argv is a bridge from the command line to your code. If you want it 
to appear that arguments come from a command line, you can assign/append 
to it.

Just going by the docs and code, one way is to assign the attribute 
named by ScriptEngine.ARGV in the ScriptContext of the engine. If it 
exists, this gets copied as sys.argv on every eval(). (This seems a 
slightly odd design to me. Why not once at engine creation?)

Jeff Allen

On 27/06/2019 07:31, Евгений Король wrote:
> Hello. How to pass arguments from Java args to jython using JSR-223?
> For example when i use code like this:
>
> ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
>
>          // Using the eval() method on the engine causes a direct
>          // interpretataion and execution of the code string passed into it
>          engine.eval("import sys");
>
> How can i pass args to Jython?
>
>
> _______________________________________________
> Jython-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jython-users
>

--------------A40B959ED238F3C841660711
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi Евгений:</p>
    <p>sys.argv is a bridge from the command line to your code. If you
      want it to appear that arguments come from a command line, you can
      assign/append to it.</p>
    <p>Just going by the docs and code, one way is to assign the
      attribute named by ScriptEngine.ARGV in the ScriptContext of the
      engine. If it exists, this gets copied as sys.argv on every
      eval(). (This seems a slightly odd design to me. Why not once at
      engine creation?)<br>
    </p>
    <pre class="moz-signature" cols="72">Jeff Allen
</pre>
    <div class="moz-cite-prefix">On 27/06/2019 07:31, Евгений Король
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CA+Mbm5xSBL8py406mKto75Z4Pm62SrY37eyeiWyW-+=b95NguA@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">Hello. How to pass arguments from Java args to jython using JSR-223?
For example when i use code like this:

ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");

        // Using the eval() method on the engine causes a direct
        // interpretataion and execution of the code string passed into it
        engine.eval("import sys");

How can i pass args to Jython?


_______________________________________________
Jython-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/jython-users">https://lists.sourceforge.net/lists/listinfo/jython-users</a>

</pre>
    </blockquote>
  </body>
</html>

--------------A40B959ED238F3C841660711--


--===============7500847036013258702==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============7500847036013258702==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users

--===============7500847036013258702==--