automatic call a function in a program
Hi,
I have a program and want to call automatically another function in my program . for example int main (){ myprogram gambitToFoam "gambitmesh" return 0; } |
Hi Gerard!
in your case, wouldn't it be more adequate to change your program into a shell or python script? If you just manipulate data an/or files, this is the most portable and efficient way of doing it. Else, you still have the call to system() from <stdlib.h>, but you will need to make sure you find the executable, i.e. you might need to input the full path. This has the drawback that you will need to recompile your code every time you change the executable (here gambitToFoam) is in another location. The shell/python/perl/etc... scripts on the other can get the path to the executable from the environment variables. It's up to you to decide which strategy suits you best. |
Hi Frank ,
I have a c++ code and don't want to transform the code in a script . my problem is that I want at some place of my program to call the function GambitToFoam without having to tipp it myself . |
Quote:
There is also a Foam::system(const string&) available from OSspecific, so you can also call it with C++ strings. |
hi Mark,
thanks for your advice. the problem it is not possible with Foam::system(const string&) to solve my problem. I want to call this function fluentMeshToFoam file.msh where file.msh is the fluent mesh and fluentMeshToFoam convert it to OpenFoam |
Quote:
What problem does the system report when you call the function? Code:
#include "OSspecific.H" |
Quote:
Fehler: »fluentMeshToFoam« wurde in diesem Gültigkeitsbereich nicht definiert that means fluentMeshToFoam ist not defined in this scope |
This is not very surprising: Your environment variables are not loaded, so the OpenFOAM paths are not available and so is the executable fluentMeshToFoam... What I said earlier: Make sure that the path is set before calling the executable. If I were you, I'd try:
system("<myPathToTheOFInstallationDir>/etc/bashrc; fluentMeshToFoam file.mesh"); |
Quote:
Code:
system("echo PATH=$PATH | sed -e 's/:/\\n/g'"); |
hi Mark ,Frank,
thanks for your help . it works Gerard |
All times are GMT -4. The time now is 21:32. |