process handling unter windows
-
hmm... danke.
kannst du mir vl. noch einen tipp geben,
wie ich dann (wenn ich ne windose aufgetrieben habe)
die source heraus "kopieren" kann?
ich hab einen debuger bis jetzt fuer anderes gebraucht
danke,
ghost
-
xGhost schrieb:
wie ich dann (wenn ich ne windose aufgetrieben habe)
die source heraus "kopieren" kann?Verstehe ich nicht ganz... Kopieren darfst Du prinzipiell nix, da der Source Du ja nicht das Recht an dem Source hast...
PS: VC++ Express 2005 ist in der aktuellen c´t kostenlos dabei...
-
ich will es auch nicht kopieren.
ich will es nur vergleichen.das problem, popen:
ich habe keine pid.
es wird in einer konsole geoeffnet, die aber lehr bleibt.also muss ich es wohl selbst integrieren,
und die noetigen parameter aendern.das programm ist opensource, so wie alles was ich mache.
gg
-
das man mit dieser klicker *** arbeiten kann *respekt*
ich bleibe lieber beim evektiven coden im emacs.muss es wohl anders versuchen.
danke trotzdem für eure hilfe.gg
-
gehts noch?
-
jo, glaube schon.
fuer mich ist dieses rumgeklicke einfach kein leben.
leider sind die sourcen unter windows not open.
naja. mal weiter schauen.
-
versuche es mal so...
extern "C" { #include <cstdio> #include <signal.h> #include <unistd.h> //define int popen_pid; #ifdef __WIN32__ #include <windows.h> #include <fcntl.h> #include <io.h> #include <stdlib.h> HANDLE my_pipein, my_pipeout, my_pipeerr; char my_popenmode; static int my_pipe(HANDLE *readwrite){ SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); /* Laenge in Byte */ sa.bInheritHandle = 1; /* Descriptoren sollen vererbbar sein */ sa.lpSecurityDescriptor = NULL; if (! CreatePipe (&readwrite,&readwrite,&sa,1 << 13)){ errno = EMFILE; return -1; } return 0; } FILE * pt_popen(const char *cmd, const char mode){ FILE *fptr = (FILE *)0; PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; my_pipein = GetStdHandle(STD_INPUT_HANDLE); my_pipeout = GetStdHandle(STD_OUTPUT_HANDLE); my_popenmode = mode; if (my_popenmode != 'r' && my_popenmode != 'w') return NULL; /* Erzeuge die Pipes... */ if (my_pipe(my_pipein) == -1 || my_pipe(my_pipeout) == -1) return NULL; /* * Erzeuge jetzt den Sohnprozess */ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO)); siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.hStdInput = my_pipein; siStartInfo.hStdOutput = my_pipeout; siStartInfo.hStdError = my_pipeout; siStartInfo.dwFlags = STARTF_USESTDHANDLES; popen_pid = CreateProcess(NULL, (LPTSTR)cmd, // command line NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited DETACHED_PROCESS, // creation flags: Ohne Fenster (?) NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION if (!popen_pid) return NULL; /* * Diese Handles gehoeren dem Sohnprozess */ CloseHandle(my_pipein); my_pipein = GetStdHandle(STD_INPUT_HANDLE); CloseHandle(my_pipeout); my_pipeout = GetStdHandle(STD_OUTPUT_HANDLE); if(my_popenmode == 'r'){ fptr = _fdopen(_open_osfhandle((long)my_pipeout, _O_BINARY),"r"); }else{ fptr = _fdopen(_open_osfhandle((long)my_pipein, _O_BINARY),"w"); } if(!fptr){ if(my_pipein != INVALID_HANDLE_VALUE) CloseHandle(my_pipein); if(my_pipein != INVALID_HANDLE_VALUE) CloseHandle(my_pipeout[0]); if(my_pipeout != INVALID_HANDLE_VALUE) } return fptr; } int pt_pclose(FILE *fle){ if (fle){ (void)fclose(fle); if (my_popenmode == 'r') CloseHandle(my_pipein); else CloseHandle(my_pipeout); return 0; } return -1; } void pt_kill(void){ TerminateProcess((void *)popen_pid, PROCESS_TERMINATE); } #else // Windows end
-
Nur so als kleiner Hinweis:
Das casten des zweiten Parameters von "cmd" (also const char*) nach "LPTSTR" ist falsch, da dies nicht mit Unicode geht. Und wenn Du es für Unicode hinbekommen würdest, würde es abstürzen:
http://blog.kalmbachnet.de/?postid=62
-
static int my_pipe(HANDLE *readwrite){ SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); /* Laenge in Byte */ sa.bInheritHandle = 1; /* Descriptoren sollen vererbbar sein */ sa.lpSecurityDescriptor = NULL; if (! CreatePipe (&readwrite,&readwrite,&sa,1 << 13)){ errno = EMFILE; return -1; } return 0; } FILE * pt_popen(const char *cmd, const char mode){ FILE *fptr = (FILE *)0; PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; my_pipein = GetStdHandle(STD_INPUT_HANDLE); my_pipeout = GetStdHandle(STD_OUTPUT_HANDLE); my_popenmode = mode; if (my_popenmode != 'r' && my_popenmode != 'w') return NULL; /* Erzeuge die Pipes... */ if (my_pipe(my_pipein) == -1 || my_pipe(my_pipeout) == -1) return NULL;zu
static int my_pipe(HANDLE *read, HANDLE *write){ SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); /* Laenge in Byte */ sa.bInheritHandle = 1; /* Descriptoren sollen vererbbar sein */ sa.lpSecurityDescriptor = NULL; if (! CreatePipe (&read,&write,&sa,1 << 13)){ errno = EMFILE; return -1; } return 0; } FILE * pt_popen(const char *cmd, const char mode){ FILE *fptr = (FILE *)0; PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; my_pipein = GetStdHandle(STD_INPUT_HANDLE); my_pipeout = GetStdHandle(STD_OUTPUT_HANDLE); my_popenmode = mode; if (my_popenmode != 'r' && my_popenmode != 'w') return NULL; /* Erzeuge die Pipes... */ if (my_pipe(my_pipeout, my_pipein) == -1) return NULL;
-
Jochen Kalmbach schrieb:
Nur so als kleiner Hinweis:
Das casten des zweiten Parameters von "cmd" (also const char*) nach "LPTSTR" ist falsch, da dies nicht mit Unicode geht. Und wenn Du es für Unicode hinbekommen würdest, würde es abstürzen:
http://blog.kalmbachnet.de/?postid=62gut, danke
-