Willkommen ~Gast!
Registrieren || Einloggen || Hilfe/FAQ || Staff
Probleme mit der Registrierung im Forum? Melde dich unter registerEin Bild.
Autor Beitrag
000
26.03.2002, 00:46
Diablo_bth



also ich hab zwei kurze Fragen:

1. also weiß jemand wie man den standart-consolen-output von einem anderen programm lesen kann? möglich sein muss das - man denke z.B. an das "process-window" von wc oder diese komische console von quark.

2. kennt irgendjemand ne url zum source der q2-comtiler-tools oder hat den jemand auf der platte rumfahren? ich kenn mitlerweile den ftp-server von id schon fast ausweding und google hat mir da auch nicht wirklich geholfen. wäre echt hilfreich wenn da jemand ne antwort hätte!

--

zum Seitenanfang zum Seitenende Profil || Suche
001
26.03.2002, 00:53
Kriz



Hm, das sind Pipelines. Die gibt es auch in Windows. Aber da muß ich selber erstmal nachschauen. Ansonsten wenn's für Linux sein soll, mußte mal Prefect fragen.

--

K:R-I)Z++
"CSS ist cascading style sheets. Und nicht so'n Ranzspiel." - dp
In memory of Voice († 2005/03/30)

zum Seitenanfang zum Seitenende Profil || Suche
002
26.03.2002, 01:11
Diablo_bth



Pipelines? hmmmm... kannst du vielleicht noch ein klitze kleines bischen konkreter werden? - wäre cool wenn du da nachschauen könntest ( vorausgesetzt es macht dir nicht zu viele umstände *schleim* )

--

zum Seitenanfang zum Seitenende Profil || Suche
003
26.03.2002, 01:40
Kriz



Wird lange....

----------------------

_pipe

Creates a pipe for reading and writing.

int _pipe( int *phandles, unsigned int psize, int textmode );

Routine Required Header Optional Headers Compatibility
_pipe <io.h> <fcntl.h>,1 <errno.h>2 Win 95, Win NT

1 For _O_BINARY and _O_TEXT definitions.

2 errno definitions.

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_pipe returns 0 if successful. It returns –1 to indicate an error, in which case errno is set to one of two values: EMFILE, which indicates no more file handles available, or ENFILE, which indicates a system file table overflow.

Parameters

phandles[2]

Array to hold read and write handles

psize

Amount of memory to reserve

textmode

File mode

Remarks

The _pipe function creates a pipe. A pipe is an artificial I/O channel that a program uses to pass information to other programs. A pipe is similar to a file in that it has a file pointer, a file descriptor, or both, and can be read from or written to using the standard library‚s input and output functions. However, a pipe does not represent a specific file or device. Instead, it represents temporary storage in memory that is independent of the program‚s own memory and is controlled entirely by the operating system.

_pipe is similar to _open but opens the pipe for reading and writing, returning two file handles instead of one. The program can use both sides of the pipe or close the one it does not need. For example, the command processor in Windows NT creates a pipe when executing a command such as

PROGRAM1 | PROGRAM2

The standard output handle of PROGRAM1 is attached to the pipe‚s write handle. The standard input handle of PROGRAM2 is attached to the pipe‚s read handle. This eliminates the need for creating temporary files to pass information to other programs.

The _pipe function returns two handles to the pipe in the phandles argument. The element phandles[0] contains the read handle, and the element phandles[1] contains the write handle. Pipe file handles are used in the same way as other file handles. (The low-level input and output functions _read and _write can read from and write to a pipe.) To detect the end-of-pipe condition, check for a _read request that returns 0 as the number of bytes read.

The psize argument specifies the amount of memory, in bytes, to reserve for the pipe. The textmode argument specifies the translation mode for the pipe. The manifest constant _O_TEXT specifies a text translation, and the constant _O_BINARY specifies binary translation. (See fopen for a description of text and binary modes.) If the textmode argument is 0, _pipe uses the default translation mode specified by the default-mode variable _fmode.

In multithreaded programs, no locking is performed. The handles returned are newly opened and should not be referenced by any thread until after the _pipe call is complete.

In order to use the _pipe function to communicate between a parent and a child process, each process must have only one handle open on the pipe. The handles must be opposites: if the parent has a read handle open, then the child must have a write handle open. The easiest way to do this is to OR (|) the _O_NOINHERIT flag with textmode. Then, use _dup or _dup2 to create an inheritable copy of the pipe handle you wish to pass to the child. Close the original handle, and spawn the child process. Upon returning from the spawn call, close the 'duplicate' handle in the parent process. See Example 2 below for more information.

In Windows NT and Windows 95, a pipe is destroyed when all of its handles have been closed. (If all read handles on the pipe have been closed, writing to the pipe causes an error.) All read and write operations on the pipe wait until there is enough data or enough buffer space to complete the I/O request.

Example 1

/* PIPE.C: This program uses the _pipe function to pass streams of
* text to spawned processes.
*/

#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <math.h>

enum PIPES { READ, WRITE }; /* Constants 0 and 1 for READ and WRITE */
#define NUMPROBLEM 8

void main( int argc, char *argv[] )
{

int hpipe[2];
char hstr[20];
int pid, problem, c;
int termstat;

/* If no arguments, this is the spawning process */
if( argc == 1 )
{

setvbuf( stdout, NULL, _IONBF, 0 );

/* Open a set of pipes */
if( _pipe( hpipe, 256, O_BINARY ) == -1 )
exit( 1 );

/* Convert pipe read handle to string and pass as argument
* to spawned program. Program spawns itself (argv[0]).
*/
itoa( hpipe[READ], hstr, 10 );
if( ( pid = spawnl( P_NOWAIT, argv[0], argv[0],
hstr, NULL ) ) == -1 )
printf( "Spawn failed" );

/* Put problem in write pipe. Since spawned program is
* running simultaneously, first solutions may be done
* before last problem is given.
*/
for( problem = 1000; problem <= NUMPROBLEM * 1000; problem += 1000)
{

printf( "Son, what is the square root of %d?\n", problem );
write( hpipe[WRITE], (char *)&problem, sizeof( int ) );

}

/* Wait until spawned program is done processing. */
_cwait( &termstat, pid, WAIT_CHILD );
if( termstat & 0x0 )
printf( "Child failed\n" );

close( hpipe[READ] );
close( hpipe[WRITE] );

}

/* If there is an argument, this must be the spawned process. */
else
{

/* Convert passed string handle to integer handle. */
hpipe[READ] = atoi( argv[1] );

/* Read problem from pipe and calculate solution. */
for( c = 0; c < NUMPROBLEM; c++ )
{

read( hpipe[READ], (char *)&problem, sizeof( int ) );
printf( "Dad, the square root of %d is %3.2f.\n",
problem, sqrt( ( double )problem ) );

}
}
}

Output

Son, what is the square root of 1000?
Son, what is the square root of 2000?
Son, what is the square root of 3000?
Son, what is the square root of 4000?
Son, what is the square root of 5000?
Son, what is the square root of 6000?
Son, what is the square root of 7000?
Son, what is the square root of 8000?
Dad, the square root of 1000 is 31.62.
Dad, the square root of 2000 is 44.72.
Dad, the square root of 3000 is 54.77.
Dad, the square root of 4000 is 63.25.
Dad, the square root of 5000 is 70.71.
Dad, the square root of 6000 is 77.46.
Dad, the square root of 7000 is 83.67.
Dad, the square root of 8000 is 89.44.

Example 2

// This is a simple filter application. It will spawn
// the application on command line. But before spawning
// the application, it will create a pipe that will direct the
// spawned application's stdout to the filter. The filter
// will remove ASCII 7 (beep) characters.

// Beeper.Cpp

/* Compile options needed: None */
#include <stdio.h>
#include <string.h>

int main()
{
int i;
for(i=0;i<100;++i)
{
printf("\nThis is speaker beep number %d... \n\7", i+1);
}
return 0;
}

// BeepFilter.Cpp
/* Compile options needed: none
Execute as: BeepFilter.exe <path>Beeper.exe
*/
#include <windows.h>
#include <process.h>
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

#define OUT_BUFF_SIZE 512
#define READ_HANDLE 0
#define WRITE_HANDLE 1
#define BEEP_CHAR 7

char szBuffer[OUT_BUFF_SIZE];

int Filter(char* szBuff, ULONG nSize, int nChar)
{
char* szPos = szBuff + nSize -1;
char* szEnd = szPos;
int nRet = nSize;

while (szPos > szBuff)
{
if (*szPos == nChar)
{
memmove(szPos, szPos+1, szEnd - szPos);
--nRet;
}
--szPos;
}
return nRet;
}

int main(int argc, char** argv)
{
int nExitCode = STILL_ACTIVE;
if (argc >= 2)
{
HANDLE hProcess;
int hStdOut;
int hStdOutPipe[2];

// Create the pipe
if(_pipe(hStdOutPipe, 512, O_BINARY | O_NOINHERIT) == -1)
return 1;

// Duplicate stdout handle (next line will close original)
hStdOut = _dup(_fileno(stdout));

// Duplicate write end of pipe to stdout handle
if(_dup2(hStdOutPipe[WRITE_HANDLE], _fileno(stdout)) != 0)
return 2;

// Close original write end of pipe
close(hStdOutPipe[WRITE_HANDLE]);

// Spawn process
hProcess = (HANDLE)spawnvp(P_NOWAIT, argv[1],
(const char* const*)&argv[1]);

// Duplicate copy of original stdout back into stdout
if(_dup2(hStdOut, _fileno(stdout)) != 0)
return 3;

// Close duplicate copy of original stdout
close(hStdOut);

if(hProcess)
{
int nOutRead;
while (nExitCode == STILL_ACTIVE)
{
nOutRead = read(hStdOutPipe[READ_HANDLE],
szBuffer, OUT_BUFF_SIZE);
if(nOutRead)
{
nOutRead = Filter(szBuffer, nOutRead, BEEP_CHAR);
fwrite(szBuffer, 1, nOutRead, stdout);
}

if(!GetExitCodeProcess(hProcess,(unsigned long*)&nExitCode))
return 4;
}
}
}

printf("\nPress \'ENTER\' key to continue... ");
getchar();
return nExitCode;
}

Process and Environment Control Routines

See Also _open

------------------------------------------------

_pclose

Waits for new command processor and closes stream on associated pipe.

int _pclose( FILE *stream );

Routine Required Header Compatibility
_pclose <stdio.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_pclose returns the exit status of the terminating command processor, or –1 if an error occurs. The format of the return value is the same as that for _cwait, except the low-order and high-order bytes are swapped.

Parameter

stream

Return value from previous call to _popen

Remarks

The _pclose function looks up the process ID of the command processor (CMD.EXE) started by the associated _popen call, executes a _cwait call on the new command processor, and closes the stream on the associated pipe.

Process and Environment Control Routines

See Also _pipe, _popen

------------------------------------------------------

_popen, _wpopen

Creates a pipe and executes a command.

FILE *_popen( const char *command, const char *mode );

FILE *_wpopen( const wchar_t *command, const wchar_t *mode );

Routine Required Header Compatibility
_popen <stdio.h> Win 95, Win NT
_wpopen <stdio.h> or <wchar.h> Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns a stream associated with one end of the created pipe. The other end of the pipe is associated with the spawned command‚s standard input or standard output. The functions return NULL on an error.

Parameters

command

Command to be executed

mode

Mode of returned stream

Remarks

The _popen function creates a pipe and asynchronously executes a spawned copy of the command processor with the specified string command. The character string mode specifies the type of access requested, as follows:

"r"

The calling process can read the spawned command‚s standard output via the returned stream.

"w"

The calling process can write to the spawned command‚s standard input via the returned stream.

"b"

Open in binary mode.

"t"

Open in text mode.

Note The _popen function returns an invalid file handle, if used in a Windows program, that will cause the program to hang indefinitely. _popen works properly in a Console application. To create a Windows application that redirects input and output, read the section "Creating a Child Process with Redirected Input and Output" in the Win32 SDK.

_wpopen is a wide-character version of _popen; the path argument to _wpopen is a wide-character string. _wpopen and _popen behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tpopen _popen _popen _wpopen

Example

/* POPEN.C: This program uses _popen and _pclose to receive a
* stream of text from a system process.
*/

#include <stdio.h>
#include <stdlib.h>

void main( void )
{

char psBuffer[128];
FILE *chkdsk;

/* Run DIR so that it writes its output to a pipe. Open this
* pipe with read text attribute so that we can read it
* like a text file.
*/
if( (chkdsk = _popen( "dir *.c /on /p", "rt" )) == NULL )
exit( 1 );

/* Read pipe until end of file. End of file indicates that
* CHKDSK closed its standard out (probably meaning it
* terminated).
*/
while( !feof( chkdsk ) )
{
if( fgets( psBuffer, 128, chkdsk ) != NULL )
printf( psBuffer );
}

/* Close pipe and print return value of CHKDSK. */
printf( "\nProcess returned %d\n", _pclose( chkdsk ) );
}

Output

Volume in drive C is CDRIVE
Volume Serial Number is 0E17-1702

Directory of C:\dolphin\crt\code\pcode

05/02/94 01:05a 805 perror.c
05/02/94 01:05a 2,149 pipe.c
05/02/94 01:05a 882 popen.c
05/02/94 01:05a 206 pow.c
05/02/94 01:05a 1,514 printf.c
05/02/94 01:05a 454 putc.c
05/02/94 01:05a 162 puts.c
05/02/94 01:05a 654 putw.c
8 File(s) 6,826 bytes
86,597,632 bytes free

Process returned 0

Process and Environment Control Routines

See Also _pclose, _pipe

--

K:R-I)Z++
"CSS ist cascading style sheets. Und nicht so'n Ranzspiel." - dp
In memory of Voice († 2005/03/30)

zum Seitenanfang zum Seitenende Profil || Suche
004
26.03.2002, 07:32
mani



uhm, ganzschön umfangreich, irgendwann mal lesen;

als ich das topic gelesen hab, erwartete ich eigentlich ne frage die ich mir auch stelle, dies war aber nicht so, deswegen gleich meine frage hierrin:

Ich will stdout der konsole abfangen und ersetzen:

z.b.

"Enter ya pw\n"
blubb

da kommts nicht gut wenn das pw dann dasteht, ich will da sterne haben D:

--

zum Seitenanfang zum Seitenende Profil || Suche
005
26.03.2002, 09:02
Tomz



fang immer die einzelnen zeichen mit einem getch und gib nicht das passwort aus, sondern einfach nur sterne... schau aber, dass wenn du dann löscht, das die sterne auch wegkommen...

sollte eigentlich ganz einfach zum coden sein. falls ich zeit habe und du es noch brauchst kann ich es schnell machen, aber jetz muss ich in die schule...

--

...denn das atombrot wird nicht ruhen bis es den letzten erwischt hat...

zum Seitenanfang zum Seitenende Profil || Suche
006
26.03.2002, 10:25
Diablo_bth



@Kriz: BIG THX!

--

zum Seitenanfang zum Seitenende Profil || Suche
007
30.03.2002, 02:30
Leviathan



@mani: hier ein programmvorschlag für dein problem (in c):

#include<stdio.h>
#include<conio.h>

void main()
{
char password[1024]=""; //Hier kommt später die Eingabe rein
char * tmp=0; //"Schleifenzähler"

printf("Passwort eingeben: ");
for(tmp=password;(tmp-password<1024);) //den string zeichenweise durchgehen bis stringlänge erreicht
{
if((*tmp=getch())==13) //Zeichen einlesen und im string ablegen, wenn gleich 13 (ENTER-Taste), aufhören
{
break;
}
if(*tmp==8) //8: BACKSPACE
{
if(tmp>password) //schon etwas eingegeben?
{
printf("\b \b");//Backspace schreiben, Zeichen löschen und nochmal Backspace schreiben
--tmp; //Zähler dekrementieren
}
}
else
{
printf("*"); //das * ausgeben
++tmp; //Zähler inkrementieren
}
}
*tmp=0; //Nullzeichen an den string anhängen
tmp=0; //Zeiger sichern

printf("\n\nEingegebenes Passwort: %s",password);
}

ich hoffe du verstehst es, wenn nicht, frag nochmal.

diese zeilenumbrüche gehen mir irgentwie auf den keks...

--

Entities: HL | HL²
Kompilierfehler
r_speeds | mehr über r_speeds


Dieser Beitrag wurde am 30.03.2002 um 02:31 von Leviathan bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
008
30.03.2002, 09:17
mani



naja, :D die backspace funktion wird abgeschaltet
Quellcode:
#include<stdio.h>
#include<conio.h>

#define MAX_C 200

void EnterPw(char password[MAX_C])
{
char * tmp=0; //"Schleifenzähler" lass ich einfach mal so ;)
for(tmp=password;(tmp-password<MAX_C);) //den string zeichenweise durchgehen bis stringlänge erreicht
{
if((*tmp=getch())==13) //Zeichen einlesen und im string ablegen, wenn gleich 13 (ENTER-Taste), aufhören
{
break;
}
if(*tmp==8) //8: BACKSPACE
{
if(tmp>password) //schon etwas eingegeben?
{
printf("\b \b");//Backspace schreiben, Zeichen löschen und nochmal Backspace schreiben
--tmp; //Zähler dekrementieren
}
}
else
{
printf("*"); //das * ausgeben
++tmp; //Zähler inkrementieren
}
}
tmp='\0'; //Nullzeichen an den string anhängen öhm kA :D ab deins jez richtig war
tmp=0; //Zeiger sichern

printf("\n\nEingegebenes Passwort: %s",password);

return;
}

void main()
{
char password[MAX_C]=""; //Hier kommt später die Eingabe rein

printf("Passwort eingeben: ");
EnterPw(password);
}

mkay, wenn du erlaubst, nehme ich diese funktion in meine lib auf ?!

--


Dieser Beitrag wurde am 30.03.2002 um 09:39 von mani bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
009
30.03.2002, 13:24
Leviathan



jaja, nimm ruhig auf, is eh nur heute nacht in 15 minuten zusammengeschrieben. allerdings würde ich folgenden prototyp empfehlen:

void EnterPw(char * pw,long length)

das ist allgemeiner, und in der stl oder der alten c-standartbibliothek haben sie es auch so gemacht (guck dir mal strncmp oder sowas an).
ich glaub das nehme ich mir auch mal in meine lib auf.

zum eigentlichen thema:
sehe ich das richtig das _popen do eine art neuen threat macht und seine ausgaben abfängt?

--

Entities: HL | HL²
Kompilierfehler
r_speeds | mehr über r_speeds

zum Seitenanfang zum Seitenende Profil || Suche