[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] "python myscript.py".unixCmd



Hi,
If by chance you'd like to "pipe" python code through sc code, you
could use Pipe (http://doc.sccode.org/Classes/Pipe.html)
This is a quick-and-dirty example (adapted from a fluidsynth interface
i wrote) that could be useful:
https://gist.github.com/lvm/c5af0ce6d79725c5d6f18c42ee55096e

Saludos,
Mauro


On Wed, Jan 3, 2018 at 6:19 PM,  <jymminbusch@xxxxxxxxx> wrote:
> Hi,
>
>
> The String "python myscript.py“ is the command you want to execute with your
> system’s standard shell.
> unixCmd is an instance method of the String class, documented here:
> http://doc.sccode.org/Classes/String.html#-unixCmd
>
> The method name suggests that it doesn’t work on windows.
>
> A simple example might look like this:
>
> In SuperCollider write:
>
> "python ~/Desktop/hello_sc.py“.unixCmd;
>
>
> The python script is expected to be sitting on the Desktop in this example,
> with a name of "hello_sc.py"
> It could contain something simple like this:
> #!/usr/bin/env python2
> print("Hello SuperCollider")
> print("This is the second Line")
>
>
> If you want to get something back from your script, you can use
> .unixCmdGetStdOut or .unixCmdGetStdOutLines.
> With the example script, the later would return an array of two elements
> (the two lines printed by the python script).
>
> a = "python3 ~/Desktop/hello_sc.py".unixCmdGetStdOutLines;
> a.postln;
> // -> [ Hello SuperCollider, This is the second Line ]
>
> If you want to pass arguments into the script you could use string formating
> in SuperCollider (see http://doc.sccode.org/Classes/String.html#-format )
>
> ~myFirstArgument = 1234 // Whatever you want to pass in
> "python3 ~/Desktop/hello_sc.py %".format(~myFirstArgument).unixCmd;
>
> and on the python side you would use one of the several options to parse
> command line arguments.
> Here’s a quick one:
>
> #!/usr/bin/env python2
> import sys
> if len(sys.argv) > 1:
> print( "Your first argument was {}".format(sys.argv[1]) )
> print("Hello SuperCollider“)
> print("This is the second Line")
>
>
>
> I think that’s pretty much it. ._.
>
> Best,
> Eric
>
>
>
> Am 03.01.2018 um 18:40 schrieb kewping@xxxxxxxxx:
>
>
> Anyone have good example/tutorial for "python myscript.py".unixCmd
>
> One of the reader said "Run python as a subprocess of SC, e.g. "python
> myscript.py".unixCmd. "
>
> This is because part of my code written in SC and python.
>
>
>
>
> --
> Sent from:
> http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.):
> http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: https://listarc.bham.ac.uk/marchives/sc-users/
> search: https://listarc.bham.ac.uk/lists/sc-users/search/
>
>

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/