[so] Citire comenzi de la tastatura

Stefan Munteanu stef8803 at yahoo.co.uk
Sat Mar 13 15:45:36 EET 2010


Salut,

Am urmatorul cod si observ ca dupa ce dau o comanda, nu mai pot scrie nimic la standard input.
Am incercat mai multe variante pt citire, dar toate au probleme. Astfel:

ReadFile, citeste si executa o comanda, apoi imi intoarce inputul caracter cu caracter (nu mai asteapta pana la newline).
scanf("%[^\n",buffer); // citeste o comanda, apoi executa aceeasi comanda la infinit

#include<iostream>
#include<windows.h>
#include<string>

using namespace std;

int main(){
    PROCESS_INFORMATION pi = {0};
    STARTUPINFO si = {0};
    string line;
    while(1){
        getline(cin,line);
        if(CreateProcess(0,(LPSTR)line.c_str(),0,0,false,CREATE_NEW_PROCESS_GROUP,0,0,&si,&pi)){
            CloseHandle(pi.hThread);
            WaitForSingleObject(pi.hProcess, INFINITE);
            CloseHandle(pi.hProcess);
        }
    }
    return 0;
}

Mai trebuie setate niste flaguri la crearea procesului?

Multumesc,
Stefan



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20100313/2e43c3d4/attachment.htm>


More information about the so mailing list