- #include <iostream>
- #include <fstream> // debug
- #include <string>
- #include <thread>
- #include <chrono>
-
- int
- main(int argc, char *argv[]) {
-
- std::ofstream log("childProgram.log");
-
- // Output for read test.
- if (argc == 2) {
-
- // Write a single line and exit.
- if (std::string(argv[1]) == "write") {
- log << "Command is \"write\". Returning \"This is a test\"" << std::endl;
- std::cout << "This is a test";
- std::cout.flush();
-
- goto exit;
-
- }
-
- // Exit without writing anything.
- if (std::string(argv[1]) == "quit") {
- log << "Command is \"quit\". Exiting" << std::endl;
-
- goto exit;
-
- }
-
- }
-
- char ch;
- log << "Received \"";
- while (std::cin >> ch) {
-
- // Exit?
- if ('q' == ch) {
- log << (char) ch << "\"" << std::endl;
- break;
-
- }
-
- std::cout << (char) std::toupper(ch);
- std::cout.flush();
- log << (char) ch;
- log.flush();
-
- }
-
- exit:
- log.close();
- std::this_thread::sleep_for(std::chrono::milliseconds(50));
- return 25;
-
- }
|