I have a cpp application that I have compiled on fly machine
#include <string>
int main() {
std::string input;
std::cout << "Please enter some text: ";
std::getline(std::cin, input);
std::cout << "You entered: " << input << std::endl;
return 0;
}
I want to run the compiled executable like this ./program < input.txt
.
contents of input.txt looks like this Hello, this is input from a file.
When I send that command over their REST API
{
"cmd": "./program < input.txt"
}
, I get an error
{
"error": "deadline_exceeded: Post \"http://unix/v1/exec\": context deadline exceeded"
}
I think it is because of the input redirection command or the cin
?? Any idea on what to do now?
Apparently this cmd
argument is not interpreted by a shell. This means that your program receives the literal arguments <
and input.txt
but nothing is ever sent to STDIN.
If you wrap your command in a bash -c
invocation the shell will do that for you:
bash -c './program < input.txt'