Ask a Question related to UNIX Programming, Design and Development.
-
wrocha #1
GETPID after popen command
Hi guys.
I have some shell scripts and I want to execute them via a C program.
This C program needs:
1- Get itself PID;
2- Get PID shell script;
3- Get all messages of shell scripts;
4- Knows the status of shell scripts;
I'm trying to use popen but I don't know how to use getpid() with popen.
I appreciate your help.
Follow below an example of my program:
#include <stdio.h>
#include <stdlib.h>
pid_t pid;
int main(int argc, char** argv)
{
int rc;
if ( argc == 2)
{
FILE* fp = 0;
char command [1024];
sprintf(command,"%s 2>&1",argv[1]);
printf("\nPID=%i\n",getpid());
if ((fp = popen( command, "r")))
{
char buffer[ 1024];
buffer[sizeof( buffer) - 1] = 0;
while (fgets( buffer, sizeof( buffer) - 1, fp))
fprintf(stdout,"\n====>%s", buffer);
if (WIFEXITED(rc = pclose(fp)))
{
if (WEXITSTATUS(rc))
printf("\nFinaliou COM erro\n");
else
printf("\nFinaliou SEM erro\n");
}
}
}
}
wrocha Guest
-
popen problems in XP
I am having problems using popen in windows XP. I am running IIS 5.1 and PHP 4.3 Here is a basic piece of code that I can get to run find on... -
#22526 [Opn->Fbk]: session_start/popen hang
ID: 22526 Updated by: iliaa@php.net Reported By: iberry at raxnet dot net -Status: Open +Status: ... -
popen() doesn't for me
popen() just won't work for me, and there is no debug info to indicate why in the server logs. Can anyone shed some light on this? Any suggestions... -
#25056 [NEW]: sqlite_open/popen difference
From: M dot Boeren at guidance dot nl Operating system: Win2k PHP version: 5CVS-2003-08-12 (dev) PHP Bug Type: SQLite related... -
#22526 [Com]: session_start/popen hang
ID: 22526 Comment by: spoon at nexdot dot net Reported By: iberry at raxnet dot net Status: No Feedback Bug...



Reply With Quote

