hello-world-cpp/main.cpp
2025-01-09 22:54:12 +10:00

29 lines
856 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "process_launcher.h"
#include <iostream>
#include <string>
int main() {
std::string command;
// В зависимости от ОС, выберем команду для запуска
#ifdef _WIN32
command = "cmd /C echo Hello, World!";
#else
command = "echo Hello, World!";
#endif
// Запускаем процесс
int pid = ProcessLauncher::launch(command);
if (pid == -1) {
std::cerr << "Не удалось запустить процесс." << std::endl;
return -1;
}
std::cout << "Процесс с PID: " << pid << " запущен." << std::endl;
// Ожидаем завершения процесса
int exitCode = ProcessLauncher::waitForProcess(pid);
std::cout << "Процесс завершился с кодом: " << exitCode << std::endl;
return 0;
}