|
[Sponsors] |
OpenFOAM Mac terminal cannot execute openfile command |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 30, 2017, 08:54 |
OpenFOAM Mac terminal cannot execute openfile command
|
#1 |
New Member
Haozhong Jiang
Join Date: May 2017
Posts: 2
Rep Power: 0 |
Dear All,
I have a problem with running external shell script inside OpenFOAM, and I spent several days on it but still not fixed. Here is the problem. I wrote a C++ code to read the data from a local .txt file. Here is the .cpp file: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string line; size_t pos = 0; string token; const char * V; cout << "Starts" <<endl; ifstream vMyFile; vMyFile.open("/Users/Desktop/laminarVortexShedding/postProcessing/probes/0/U", std::fstream::in); if (vMyFile.is_open()) { int i = 0; while (! vMyFile.eof() ) { getline(vMyFile,line); if (i >= 3) { if (line.find("(") == 28) { pos = line.find("("); token = line.erase(0, pos); // pos = token.find(" "); // token = token.substr(0, pos); //cout << "i = " << i << token << endl; } } i++; } vMyFile.close(); V = token.c_str(); cout << "Last iteration velocity: " << V << endl; } else cout << "Unable to open file11111" << endl; ofstream vEstimate_file ("/Users/Desktop/laminarVortexShedding/U_estimate"); if (vEstimate_file.is_open()) { vEstimate_file << V; vEstimate_file.close(); } else cout << "Unable to open file22222" << endl; return 0; } And then I made a shell script which compile the C++ code and ./run the program. #!/bin/bash # My first script g++ -std=c++11 -o runf main.cpp ./runf In the terminal, I type ./shell.sh, everything works fine and I get the result I want. However, once I do the exact same thing in the OpenFOAM terminal window(Because OF on Mac is based on Docker? therefore I have to run it in a different terminal window, which has ofuser@98032082cf7e on the left.), it shows cannot open file. Unable to open file11111 Unable to open file22222 Can anyone give me some help on this problem? Why it won't work on the OpenFOAM terminal? Thanks a lot! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology | wyldckat | OpenFOAM | 17 | November 10, 2017 16:54 |
OpenFOAM v3.0+ ?? | SBusch | OpenFOAM | 22 | December 26, 2016 15:24 |
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | September 21, 2016 12:50 |
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | September 14, 2016 04:19 |
Is it a good idea to use OpenFoam on a Mac (OS 10.7.5) or on Windows7? | bzz77 | OpenFOAM Installation | 4 | November 21, 2012 18:06 |