Python Forum
Communicating C++ and Python in Jetson TK1 board. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Communicating C++ and Python in Jetson TK1 board. (/thread-3935.html)



Communicating C++ and Python in Jetson TK1 board. - hlfan1234567 - Jul-09-2017

I'm using Jetson TK1 board(Linux4Tegra)(almost same with ubuntu)

I followed this instruction(I can't upload clickable link yet...)


Python :

from subprocess import Popen, PIPE

p = Popen(['a.out'], shell=True, stdout=PIPE, stdin=PIPE)
for ii in range(10):
   value = str(ii) + '\n'
   #value = bytes(value, 'UTF-8')  # Needed in Python 3.
   p.stdin.write(value)
   p.stdin.flush()
   result = p.stdout.readline().strip()
   print(result)
C++ :

#include <iostream>

int main(){
   for( int ii=0; ii<10; ++ii ){
       int input;
       std::cin >> input;
       std::cout << input*2 << std::endl;
       std::cout.flush();
   }
}
Output from Python :

Output:
0 2 4 6 8 10 12 14 16 18
I installed Python properly

but Python code won't work


this is my error message.
---------------------------------------------------------------------------------------------

Error:
/bin/sh: 1: a.out: not found Traceback (most recent call last):  File "CommunicationWithSubprocess3.py", line 7, in <module>    p.stdin.write(value) IOError: [Errno 32] Broken pipe
------------------------------------------------------------------------------------------------

"Broken pipe" error message pops up.

how can I solve this problem..?


RE: Communicating C++ and Python in Jetson TK1 board. - hlfan1234567 - Jul-09-2017

I solved this problem.

I'm sorry for my mistake. I'm not familiar with this site yet.

I'm very sorry.

The problem was...

p = Popen(['a.out'], shell=True, stdout=PIPE, stdin=PIPE)
this code.

not a.out, it should include all the path to C++ executable file.