Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

childProgram.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <iostream>
  2. #include <fstream> // debug
  3. #include <string>
  4. #include <thread>
  5. #include <chrono>
  6. int
  7. main(int argc, char *argv[]) {
  8. std::ofstream log("childProgram.log");
  9. // Output for read test.
  10. if (argc == 2) {
  11. // Write a single line and exit.
  12. if (std::string(argv[1]) == "write") {
  13. log << "Command is \"write\". Returning \"This is a test\"" << std::endl;
  14. std::cout << "This is a test";
  15. std::cout.flush();
  16. goto exit;
  17. }
  18. // Exit without writing anything.
  19. if (std::string(argv[1]) == "quit") {
  20. log << "Command is \"quit\". Exiting" << std::endl;
  21. goto exit;
  22. }
  23. }
  24. char ch;
  25. log << "Received \"";
  26. while (std::cin >> ch) {
  27. // Exit?
  28. if ('q' == ch) {
  29. log << (char) ch << "\"" << std::endl;
  30. break;
  31. }
  32. std::cout << (char) std::toupper(ch);
  33. std::cout.flush();
  34. log << (char) ch;
  35. log.flush();
  36. }
  37. exit:
  38. log.close();
  39. std::this_thread::sleep_for(std::chrono::milliseconds(50));
  40. return 25;
  41. }