Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to exchange variables between c, perl and shell scripts?

Status
Not open for further replies.

pd

Full Member level 1
Joined
May 23, 2006
Messages
99
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,288
Location
India
Activity points
2,243
Hi!
Can anybody tell how can I exchange variables between c, perl and shell scripts?

For example say I have a code in C (test_return.c) as:
#include<stdio.h>
int main()
{
x=5;
return x;
}


Now I want to access the value of variable x in the shell script.How can I do that?

In the shell script I am running the exe file created from the compiled and build exe from the c code.
E.g. ./test_return.exe
Thanks,
pd
 

Hello pd,

There are two ways to enable both the shell script and a perl script (they really works for any other kind of programming language with minimal support).

[1] write down the value of the variable into a file (vars.txt, for example) and then open the file with the shell script and read the data (var's value) and do something with it.

[2] if you do know how to use the sockets functionality for C and perl you can exchange data between this to languages through a socket connection (like if they were tied with a pipe) that allows you to send/received data on every separate program.

if you do not know how to do any of this two alternatives, let me know and i can guide you to the corresponding books or links to make it happen.
 

Re: how to exchange variables between c, perl and shell scri

Thanks aadvedaboard!
I some how know the 1st option...but not about the second one....
Can you please elaborate with an example?
-pd
 

better try $? and environment vars.
 

I think sockets is the best way. It's like a virtual port. Most languages have hooks into sockets. Setting environment variables would work but it is not very elegant. Environment variables are for important, enduring things like a programs or OS settings and such. I would not want to clutter it up. If you do use environment variables, clean up after yourself (get rid of them when the programs end).
 

you can use text file for this
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top