1[section:faq Frequently Asked Questions] 2 3[section:dead_lock Why does this produce a deadlock?] 4 5Now let's revisit our c++filt example and we will put in an obvious mistake. 6This might however be not as obvious for more complex applications. 7 8``` 9vector<string> demangle(vector<string> in) 10{ 11 12 ipstream is; 13 opstream os; 14 child c("c++filt", std_out > is, std_in < os); 15 16 vector<string> data; 17 for (auto & elem : data) 18 { 19 string line; 20 getline(is, line); 21 os << elem; 22 } 23} 24 25``` 26We switched the read and write operation up, so that's causing a dead-lock. 27This locks immediately. This is because `c++filt` expects input, before 28outputting any data. The launching process on the other hand waits for its output. 29 30[endsect] 31 32[section:closep Why does the pipe not close?] 33 34Now for another example, which might look correct, let's consider you want 35to use `ls` to read the current directory. 36 37``` 38ipstream is; 39child c("ls", std_out > is); 40 41std::string file; 42while (is >> file) 43 cout << "File: " << file << endl; 44 45``` 46 47This will also deadlock, because the pipe does not close when the subprocess exits. 48So the `ipstream` will still look for data even though the process has ended. 49 50[note It is not possible to use automatic pipe-closing in this library, because 51a pipe might be a file-handle (as for async pipes on windows).] 52 53But, since pipes are buffered, you might get incomplete data if you do this: 54 55``` 56ipstream is; 57child c("ls", std_out > is); 58 59std::string file; 60while (c.running()) 61{ 62 is >> file; 63 cout << "File: " << file << endl; 64} 65``` 66 67It is therefore highly recommended that you use the asynchronous API if you are 68not absolutely sure how the output will look. 69 70[endsect] 71 72[section:wchar_t When will the codecvt be used?] 73 74Since windows does not use UTF-8 it is sometimes unavoidable to use the `wchar_t` version of the WinApi. 75To keep this library consistent it provides `wchar_t` support on posix also. 76 77Since the posix api is purely `char` every `wchar_t` based type will be converted into `char`. 78 79Windows on the other hand is more selective; the default is to use `char`, 80but if any parameter requires `wchar_t`, everything will be converted to `wchar_t`. 81This also includes `boost::filesystem::path`. Additionally, if the system does not provide 82the `char` api (as is the case with Windows CE) everything will also be converted. 83 84 85[endsect] 86 87[endsect]