Running a C++ compiled program in the background and sending input whenever needed
3
votes
3
answers
6783
views
I have a compiled program written in C++ for a UNIX environment which has this kind of structure:
int main(){
...
LoadEngine()
...
while(1){
std::cin >> buffer;
...
ExecuteFunction(buffer);
}
}
Loading the engine takes quite a while, so I'm trying to start the program in the background first, then send the input whenever I need to.
Running the program with the standard ampersand appended at the end seemingly does not make the program run in the background, but rather halts at _std::cin_ until an input is received from the console, and stops after an input is accepted from the console.
How do I execute the program such that the program runs continuously in the background and receive input and execute the function whenever it is needed?
**EDIT**: The final product is a small device (RaspberryPi) which recognizes speech, and does something based on the words recognized. The program that I have is the part where the device does something based on the word input, and the word input corresponds to the variable _buffer_ from the code snippet above.
So the _std::cin_ part is a dummy line code that I'm using for testing out that my part of the code starts up in the background process (to load the engine) and does whatever it is designed to do.
**EDIT 2** : To clarify what I’m trying to achieve, the program takes an input from a speech recognizer and does things (e.g. synthesize speech from input, send out signals to LEDs, etc.). The text input can be taken directly from the console (which my code is currently doing), or some other method that I’m not knowledgeable in. The only thing that the input adheres to is that it _must be_ a text, and is sent from another program that recognizes speech (which is handled by some other developer). So the exact method isn’t specified. All I have to worry about is my side of the program, which executes a function from a text input (i.e. _buffer_ from the code snippet).
So the general structure would look something like this:
Int main(){
LoadEngine()
while(1){
buffer = ReceiveInput();
ExecuteFunction(buffer);
}}
Where the _ReceiveInput()_ part is currently implemented as _std::cin_. It really can be any method, as long as the engine is loaded once in the beginning, and the program is able to perform _ExecuteFunction_ from an input until the device is turned off.
Asked by stock username
(33 rep)
Aug 27, 2015, 03:27 AM
Last activity: Jan 23, 2018, 07:05 PM
Last activity: Jan 23, 2018, 07:05 PM