Enviado em 17/09/2019 - 07:20h
Bom Dia galera, estou começando agora no C++ e gostaria de saber como deixar esse código executável no terminal do linux, já que a API do windows (#include <windows.h>) não permite. Agradeço desde já. Abraços#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <string>
STARTUPINFO sti = {0};
SECURITY_ATTRIBUTES sats = {0};
PROCESS_INFORMATION pi = {0};
HANDLE pipin_w, pipin_r, pipout_w, pipout_r;
BYTE buffer[2048];
DWORD writ, excode, read, available;
void ConnectToEngine(char* path)
{
pipin_w = pipin_r = pipout_w = pipout_r = NULL;
sats.nLength = sizeof(sats);
sats.bInheritHandle = TRUE;
sats.lpSecurityDescriptor = NULL;
CreatePipe(&pipout_r, &pipout_w, &sats, 0);
CreatePipe(&pipin_r, &pipin_w, &sats, 0);
sti.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
sti.wShowWindow = SW_HIDE;
sti.hStdInput = pipin_r;
sti.hStdOutput = pipout_w;
sti.hStdError = pipout_w;
CreateProcess(NULL, path, NULL, NULL, TRUE,0, NULL, NULL, &sti, &pi);
}
std::string getNextMove(std::string position)
{
std::string str;
position = "position startpos moves "+position+"\ngo\n";
WriteFile(pipin_w, position.c_str(), position.length(),&writ, NULL);
Sleep(500);
PeekNamedPipe(pipout_r, buffer,sizeof(buffer), &read, &available, NULL);
do
{
ZeroMemory(buffer, sizeof(buffer));
if(!ReadFile(pipout_r, buffer, sizeof(buffer), &read, NULL) || !read) break;
buffer[read] = 0;
str+=(char*)buffer;
}
while(read >= sizeof(buffer));
int n = str.find("bestmove");
if (n!=-1) return str.substr(n+9,4);
return "error";
}
void CloseConnection()
{
WriteFile(pipin_w, "quit\n", 5,&writ, NULL);
if(pipin_w != NULL) CloseHandle(pipin_w);
if(pipin_r != NULL) CloseHandle(pipin_r);
if(pipout_w != NULL) CloseHandle(pipout_w);
if(pipout_r != NULL) CloseHandle(pipout_r);
if(pi.hProcess != NULL) CloseHandle(pi.hProcess);
if(pi.hThread != NULL) CloseHandle(pi.hThread);
}
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
O Que Fazer Após Instalar Fedora 42
Debian 12 -- Errata - Correções de segurança
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Pra quem contribui com artigos e dicas (4)
Meu PC perde o boot de várias distros Linux após ficar desligado (1)
Alguém poderia me ajudar a escolher peças pra montar um desktop? (25)