Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

_popen, offnen einer Pipe und schreiben in die Standardeingabe

Empfohlene Antworten

Veröffentlicht

Hallo Leutz :-))

kriege es nicht hin diese Pipe aufzubauen. Wenn ich nur ein Dir Befehl durch die Pipe schicken möchte und mich an die vorgegebene Syntax halte, baut er nicht einmal die Pipe auf um das Dir durchzusenden. Muss irgendwas falsch machen, vielleicht was übersehen. Wer kann mir helfen???

Poste mal deinen Code, dann werden Sie geholfen ;)

Code posten, ok :cool: , hab das Beispiel aus der Borland Hilfe übernommen

FILE* handle; // Behandelt das eine Ende der pipe

char message[256]; // Puffer für Text, der durch die Pipe geschickt wird

int status; // Funktionsrückgabewert

handle = _popen("dir /b", "wt");

if (handle == NULL)

{

perror("_popen error");

exit(0);

}

// Liest und leitet die Eingabe weiter, die vom untergeordneten Prozeß empfangen wurde

while (fgets(message, sizeof(message), handle))

{

fprintf(stdout, message);

}

// Schließt die Pipe und prüft den Status für die Rückgabe

status = _pclose(handle);

if (status == -1)

{

perror("_pclose error");

}

handle = _popen("dir /b", "rt");

Hi,

also folgendes Beispiel aus der MSDN Library funktioniert:


#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 ) );
}
[/PHP]

EDIT:

handle = _popen("dir /b", "rt");

Dein Beispiel läuft bei mir übrigens auch egal ob "rt", oder "wt". Es

muß also an etwas anderem liegen.

Gruß

Guybrush

OK, das bringt mich zwar nicht direkt weiter, aber erstmal danke guybrush...

_popen liefert bei mir immer NULL zurück. Kann keine Pipe erzeugen und weiss einfach nicht warum.

werde dranbleiben...

Ich programmiere eine grafische Oberfläche für ein bestehendes Programm, welches ich ansteuern möchte. Das Programm ist eine Konsolenanwendung...

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.