I'm having some problems with getting the system() command to return values in a program I'm compiling and running on Debian.
My code is fairly long at this stage, so an extract from my code that shows the relevant problem is:
string fileloc("./wcstools-3.8.1/bin/sky2xy"); string fileargx("-o x"); string fileargy("-o y"); string space(" "); commandx = (fileloc + space + fileargx + space + file + space + rastr + space + decstr + space + coordsys).c_str(); commandy = (fileloc + space + fileargy + space + file + space + rastr + space + decstr + space + coordsys).c_str(); x = system(commandx); y = system(commandy); xyout << x << "\t\t" << y << endl;
where "rastr" and "decstr" are strings containing angular information in the format: ra(hh:mm:ss) & dec(dd:mm:ss), "file" is a pointer to a FITS image file (a format used in astrophysics) and "coordsys" is a coordinate system reference ("J2000" in this case).
The program compiles and runs well enough, but instead of returning a value to x and y the system() command just outputs the results to my terminal. It activates the sky2xy program (a coordinate system converting tool) and passes it the correct arguments (although it does not, as yet, give me the correct x and y values), but returns only 0s to x and y.
Should this command return a value to my program? If not, what else would you recommend to use?
A second problem is that when it does return a value, it will be an integer, not a double, for example causing 6.9 to be returned as 6. Is there any function that will execute a command in the terminal and return a double, or is there any other way around this integer problem?
Thanks for your help,