Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have previously asked a question, which is somewhat related to the present one, however, Please help a bit more.
As I understand it, from this link, I should be able to use redirect.stdin to a named pipe, then use a putc or binary write command to the pipe, and write unformatted data to it.
Nonetheless, I would love, that on the other end, a parallely running fortran process reads form one pipe, to which my D code writes in, and writes to another, from which i can read off, while in the D code.
Now problem is I don't find much information about named pipes in Fortran.
Before I use a C interface, to Fortran, is there any way to read pipes and write on a separate parallel pipe from Fortran?
EDIT: thanks for the hints, I sorted it.
I don't know much about Fortran but if you use the pipe redirection on the D side, the Fortran side just needs to use regular input read and output write functions, just like printing text to the screen, and it will be received on the D side.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
I have one anonymous pipe and two child processes. I write one number in the pipe and now i have to read it in both processes. is there any way?
I tried to GetStdHandle(STD_INPUT_HANDLE), also I tried to use cin.peek but it doesn't work for me.
You don't tell us which kind of anonymous pipes you're dealing with. However, since pipe is a UNIX concept in its core, I'll assume you're referring to POSIX pipes.
These don't support multi-reader access. A read access necessarily consumes the read bytes from the underlying buffer.
So what you want is impossible, kind of by design.
However, reading that you have two child processes, it would seem sensible to assume you could use shared memory for the actual data exchange, and some other means for synchronization of access.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I want to copy a file to another file. But it always failed. I checked my code carefully, but I still can not know what's wrong with it. So I guess may be one of the two files is being used by other process. So firstly, I want to check whether they are being used by other process.
If so, is there any solution to stop the procedure by using c++??
If your code always fails, I would assume that it's because there is a problem with the code, because that's where the problem is in approximately 99.999%1 of the cases.
That said, there isn't much point in checking if you can open a file before you try, since some other process might open (or lock, or remove, ...) the file between your checking and your opening it.
The reliable method is to just go ahead and try to open the file, and then handle failure gracefully (which you need to do anyway).
Footnotes:
1 Scientific fact that I just made up.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
First off, my company is into power grid, not IT, so software is kinda a secondary role here.
I work on a power system simulation software, very old code base in C++ with MFC, like 15 years old. What we do is take large amounts of data, ~100,000 floating point values then format and write to a text file (most of the code actually uses the C FILE structure to do this). Then, it's read by a separate engine exe which computes the electrical algorithm (Electrical algorithms are mostly numeric solutions of system of diffn equations) and then writes back huge amount of data to another text file, which we read and update the UI.
My question is, is this how it should be done? It there a way to skip writing into the text file and directly pass the data to the exes?
exes are called using CreateProcess() MFC function.
EDIT::
Sorry, site won't let me comment.
#Vlad Feinstein Well, yes, it's like a Ladder. A thing called load flow solves power flow through the lines, which in turn will be used to find stability of the systems, which in turn for overvoltage ect. It's huge, the UI is million+ lines of code, engine exes another million maybe.
Doesn't MFC already implement IPC using Dynamic Data Exchange? I can pass strings to another process's PreTranslateMessage() func. A scaled up version of that?
There is no such a thing as "should be done as ..." there are multiple methods to do IPC and while the method you describe might not be the fastest, it is a viable solution nevertheless. If the performance doesn't bother you in this particular case you should not bother with modifying it. It is exactly the case where the phrase "if it ain't broke, don't fix it" applies.
Probably, you would not want to make any new IPC in the application that way, though.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a problem. I want to rewrite txt file into other txt file, but with other encoding. I must implement conversion to Unicode, iso-8859 and windows-1250.
I must write it in c++.
Can anyone help me with this topic? How to start coding this?
Best regards!
Windows is perfectly capable of doing string conversions for you. Read data from the source file and pass it to MultiByteToWideChar specifying the source codepage, then pass that output to WideCharToMultiByte specifying the target codepage and write that output to the target file.
BTW, next question state up front that you're working on Windows only. Don't put useful information like that in a comment.
I would start by getting a good in-depth knowledge of this encoding formats, I would create some encoding conversion tables, and convert byte by byte. Also, it sounds like you are going to be dealing with different operating systems, so keep an eye out for endianness.
Here's a good link to get you started Encoding for Programmers.
EDT#1: Here is another link that goes a little more in depth on the subject of character encoding in windows. Here you can find functions and macros that can help you building your application.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to parse one text file and get 3 parameters values out of it. I want to store this data in structure array and pass this structure array to one cpp file. What kind of data structure should I use in perl and how should I collect that structure array in cpp file?
Your question is somewhat unclear. Do you want the Perl program to generate source code that goes into a .cpp file before compilation, or do you want to read the output of a Perl program from a running C++ program?
Perl has a single array type, so you would use that for both cases.
If you are just using Perl to generate code, have it write a code fragment to a file using plain print statements, then #include that in your C++ source.
If you want to read the output of a Perl script from a running C++ program, and it is simple values that do not contain spaces or otherwise need escaping, you can simply use popen(3) to launch the script and fscanf(3) to read its output; then have the Perl script just output in a fscanf-compatible format with e.g. print "#result";.