You are not logged in.

#1 2012-08-17 02:40:30

BennyBolton
Member
From: Christchurch New Zealand
Registered: 2011-10-14
Posts: 63
Website

[SOLVED] c++ get variable set by call to system()

I am writing a program and i decided for input/output it would be best to allow for custom commands. I have written a config file and defined a series of commands (just echo, etc) and call these within the program using system(). The problem is that i need to get input from these commands. I tried using "read ANSWER" and then getenv("ANSWER") but this returns a null string. What is the best method to do this?

Last edited by BennyBolton (2012-08-17 07:10:59)


HP DV6 + Arch + Openbox

Offline

#2 2012-08-17 06:58:54

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] c++ get variable set by call to system()

Use "popen()" instead of "system()".  Even better, avoid subprocesses and use C++ libraries instead.   I can't see any reason why one would call echo from C++…

Last edited by lunar (2012-08-17 06:59:43)

Offline

#3 2012-08-17 07:10:22

BennyBolton
Member
From: Christchurch New Zealand
Registered: 2011-10-14
Posts: 63
Website

Re: [SOLVED] c++ get variable set by call to system()

Thank you for the reply! This should do the trick


HP DV6 + Arch + Openbox

Offline

Board footer

Powered by FluxBB