[erlang-questions] receiving output from a python shell

Garrett Smith <>
Mon Jan 28 00:49:17 CET 2013


I would still consider using erlport and the eval function to evaluate commands:

http://docs.python.org/2/library/functions.html#eval

This will give you control over what you're doing.

Unless you're trying to literally screen-scrape Python. If that's your
goal, you'll want to run Python in interactive mode with the -i option
(man python).

1> P = erlang:open_port({spawn, "python -i"}, [stderr_to_stdout]).
#Port<0.516>
2> flush().
Shell got {#Port<0.516>,
           {data,"Python 2.7.3 (default, Aug  1 2012, 05:14:39) \n[GCC
4.6.3] on linux2\n"}}
Shell got {#Port<0.516>,
           {data,"Type \"help\", \"copyright\", \"credits\" or
\"license\" for more information.\n"}}
Shell got {#Port<0.516>,{data,">>> "}}
ok
3> erlang:port_command(P, "print 1\n").
true
4> flush().
Shell got {#Port<0.516>,{data,"1\n>>> "}}
ok

Garrett

On Sun, Jan 27, 2013 at 5:03 PM, pablo platt <> wrote:
> erlport looks interesting but I don't need to manipulate the python shell
> response.
> I want to start a python shell (or any other shell), send arbitrary commands
> to it and get the response.
>
>
> On Mon, Jan 28, 2013 at 12:53 AM, Steve Vinoski <> wrote:
>>
>>
>>
>> On Sun, Jan 27, 2013 at 4:56 PM, pablo platt <>
>> wrote:
>>>
>>> How can I get the output of a python shell?
>>>
>>> This is what I'm trying to do:
>>> > Port = open_port({spawn, "python"}, [binary, exit_status]).
>>> #Port<0.586>
>>> > port_command(Port, "print 1\n").
>>> true
>>> > flush().
>>> ok
>>>
>>> When calling flush(), I expect to get {Port,{data, <<"1\n">>}}
>>> but I'm not getting any message.
>>
>>
>> You might want to try ErlPort:
>>
>> http://erlport.org
>>
>> Otherwise, you're just going to have to re-code what ErlPort already gives
>> you.
>>
>> --steve
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list