Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to exec a python program from another C program where the return value of the py script is

int array[3]

can I grab the this array from the python exit code ??

EDIT: if the question is not clear can I make the return code of python script an array of integers instead of int ?? and catch it from C process ??

What I want to achieve?? I am working on a robot , a Raspberry PI with 3 sensors. The RPi is running arch linux, the C program is the navigator that takes input from a python script that get data from sensors, I am wondering how to get the data ??

share|improve this question
Your question is not clear. the return value from a program on common OSs is an integer. – Elazar 18 hours ago
ok can I make it an array of integers ?? – Ahmed Kato 18 hours ago
Nope. you can try to decode somehow, if the numbers are small, but no. you should use some other form of comunication - I'd say standard output. – Elazar 18 hours ago
Please give some more information about what and why are you trying to achieve. And on which OS. By the way: There is no such thing like "C process" or "Python proces". only "process". – Elazar 18 hours ago
Ok please check the last edit. – Ahmed Kato 18 hours ago

2 Answers

No. The exit code of a process is a single integer, from 0 to 255. It cannot be an array, nor can it be outside that range.

If you want to return data from a C program to its caller, print it on standard output (e.g, printf()). The exit status can only convey very basic information, like success/failure.

share|improve this answer

You can't use the exit code for this. However, you can use standard input/output:

p.py:

print 1, 2, 3

temp.c:

#include <stdio.h>

int main() {
    int array[3];
    scanf("%d%d%d", &array[0], &array[1], &array[2]);
}

run:

$ gcc temp.c
$ python p.py | ./a.out
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.