[Porcelain] how to get the return var from a script

Hey,

I’m using the Porcelain library in elixir. I would like to know how to get the return var from a php script into my elixir program.

elixir.ex
proc = %Proc{pid: pid} = Porcelain.spawn("php", ["test.php", payload], [in: :receive, out: {:send, self()}, err: {:send, self()}])

test.php
#!/usr/bin/php
<?php

      $value = $argv[1];
      return $value;
?>

i didn’t manage to get the output $value. Porcelain only send back what I echo in the php script…

If you have any experience in this library and you have solution, please don’t hesitate.

`There is no way to get the value of whatever you returned there. You weren’t even able to in PHP, if it is started as externel OS-process as you did here.

If you want to have communication between your PHP script and your Elixir programm, then you have to do it via IO of some kind. Networking, Files, Stdin/-out… There is no way around this limitation

not sure I completely understand the issue…

changing return $value; to echo $value; will make this work:

result = Porcelain.shell("php test.php 123")
and result.out will be “123”

Yes sure

A PHP return statement takes the argument you give it and passes it up the PHP stack, however if there are no other PHP functions up the PHP stack then it vanishes as the PHP script ends. To get it you will need to echo it or pass it over a pipe or whatever else as others state. :slight_smile:

1 Like