У меня есть кодовый клиент на C ++, клиент работает на Ubuntu. Когда я создаю сеанс Нью -Йорк Бэш закрыт. Почему? Если у вас есть идея, напишите, пожалуйста < /p>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
std::atomic running(true);
void signalHandler(int signal) {
if (signal == SIGINT) {
running = false;
}
}
class ShellHandler {
private:
int pipeIn[2]; // Pipe for sending input to the shell
int pipeOut[2]; // Pipe for receiving output from the shell
pid_t shellPid;
public:
ShellHandler() : pipeIn{-1, -1}, pipeOut{-1, -1}, shellPid(-1) {
// Create pipes for communication with the shell
if (pipe(pipeIn) == -1 || pipe(pipeOut) == -1) {
throw std::runtime_error("Failed to create pipes.");
}
// Fork a child process to run the shell
shellPid = fork();
if (shellPid == -1) {
throw std::runtime_error("Failed to fork.");
}
if (shellPid == 0) {
// Child process: Run the shell
close(pipeIn[1]); // Close the write end of the input pipe (не используется в дочернем процессе)
close(pipeOut[0]); // Close the read end of the output pipe (не используется в дочернем процессе)
// Redirect stdin and stdout to the pipes
if (dup2(pipeIn[0], STDIN_FILENO) == -1) {
std::cerr
Подробнее здесь: https://stackoverflow.com/questions/795 ... and-for-sh
Программа на Ubuntu Создайте трубку и используйте оболочку, но когда я хочу отправить команду для оболочки, уже закрытую ⇐ C++
Программы на C++. Форум разработчиков
1741812378
Anonymous
У меня есть кодовый клиент на C ++, клиент работает на Ubuntu. Когда я создаю сеанс Нью -Йорк Бэш закрыт. Почему? Если у вас есть идея, напишите, пожалуйста < /p>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
std::atomic running(true);
void signalHandler(int signal) {
if (signal == SIGINT) {
running = false;
}
}
class ShellHandler {
private:
int pipeIn[2]; // Pipe for sending input to the shell
int pipeOut[2]; // Pipe for receiving output from the shell
pid_t shellPid;
public:
ShellHandler() : pipeIn{-1, -1}, pipeOut{-1, -1}, shellPid(-1) {
// Create pipes for communication with the shell
if (pipe(pipeIn) == -1 || pipe(pipeOut) == -1) {
throw std::runtime_error("Failed to create pipes.");
}
// Fork a child process to run the shell
shellPid = fork();
if (shellPid == -1) {
throw std::runtime_error("Failed to fork.");
}
if (shellPid == 0) {
// Child process: Run the shell
close(pipeIn[1]); // Close the write end of the input pipe (не используется в дочернем процессе)
close(pipeOut[0]); // Close the read end of the output pipe (не используется в дочернем процессе)
// Redirect stdin and stdout to the pipes
if (dup2(pipeIn[0], STDIN_FILENO) == -1) {
std::cerr
Подробнее здесь: [url]https://stackoverflow.com/questions/79504744/program-on-ubuntu-create-pipe-and-use-shell-but-when-i-want-send-command-for-sh[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия