Python Forum
Communicating C++ and Python in Jetson TK1 board.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Communicating C++ and Python in Jetson TK1 board.
#1
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..?
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to make a board with turtle, nothing happens when running script Quascia 3 608 Nov-01-2023, 03:11 PM
Last Post: deanhystad
Photo HOW FIX MY BOARD GAME LAZABI 3 1,435 Apr-01-2022, 04:23 PM
Last Post: BashBedlam
  The game should now run and terminate once the board is full, but still can’t identif rango 0 1,429 Jul-22-2021, 03:24 AM
Last Post: rango
  Enabling interrupt on Adafruits button/led board Moris526 0 1,987 Apr-30-2021, 03:29 PM
Last Post: Moris526
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,047 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Interrupt for Adafruits Neotrellis button/led board Moris526 0 1,769 Dec-28-2020, 05:42 AM
Last Post: Moris526
  Communicating between programs shubh00 2 1,887 Oct-19-2020, 06:11 AM
Last Post: Gribouillis
  Python IDE doesn't see opencv-python package on my Jetson Nano sadhaonnisa 1 3,290 Oct-11-2020, 01:04 AM
Last Post: Larz60+
  Communicating Roblox's Inventory API with python? 4TH4RV 1 2,029 Jun-22-2020, 10:30 AM
Last Post: snippsat
  [Help] A function that generates an n x n sized board? vanicci 5 4,692 Aug-14-2018, 02:26 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020