Questions tagged [fdopen]

28 questions
2
votes
1 answer

File Locking compatible with fgets and fprintf

I am reading http://beej.us/guide/bgipc/html/multi/flocking.html for file locking, now I try to figure how to work with both file description and file pointers (I need fprintf and fgets), this code actually works but I'm not sure if flags assigned…
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
1
vote
1 answer

Problem printing popen stdout from subprocess

i need put the output command to a variable. I was trying this: import os import subprocess output = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE) print (output.stdout) output.terminate() but i get 'open file '', mode 'rb' at…
1
vote
0 answers

python os.pipe() to create pipe and open the file descriptor in c

I want to use python to create a pipe readfd, writefd = os.pipe(). And then I create a subprocess inside my python script to run some c code where it tries to open the readfd(which is an int say 5) FILE* fp = fdopen(readfd, "r"); but it returns a…
Herbert
  • 538
  • 1
  • 4
  • 15
1
vote
0 answers

Fork in C and then pass data to Python3 program with a pipe

I fork in c, call a python program from child process and pass a string from parent. Now i will print this string on my python program. I have this Code: void forking () { int thepipe[2]; char someString[] = "Hello, world!\n"; char…
Samhamsam
  • 87
  • 9
1
vote
0 answers

Is it safe to use a file descriptor and its associated FILE* stream simultaneously?

I'm writing a C++ socket library to handle the intricacies of managing socket related system calls. I'm curious if there are any harmful side effects in creating a FILE* with fdopen(3) and using it alongside the client's original file…
Clay Freeman
  • 533
  • 5
  • 17
1
vote
4 answers

Is it possible to rescue file descriptor from FILE*?

I have to use a certain cross-platform library which passes FILE* objects around. I get a file descriptor from another source (inherited), I want to keep same fd across fork'd processes. I currently use fdopen to convert a file descriptor to a FILE*…
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
0
votes
0 answers

Is there any way to safely and successfully write to a hand-picked file descriptor number, other than FD=0,1,2?

My overall objective (motivation for the question): To provide an executable ìo, from C/C++ compilation/linking, so that a user can execute it alternatively as: io 3> myout.txt. In this case myout.txt would contain whatever I explicitly send to…
0
votes
1 answer

Correct way of using fdopen

I mean to associate a file descriptor with a file pointer and use that for writing. I put together program io.cc below: int main() { ssize_t nbytes; const int fd = 3; char c[100] = "Testing\n"; nbytes = write(fd, (void *) c,…
0
votes
0 answers

Shutdown part of socket in C

Given FILE* stream = fdopen(sfd,"r+"), where sfd refers to the file descriptor of a socket, is there any function that takes a FILE* as parameter and is able to shutdown a part of the socket (ie, close the socket for write processes)? Or,…
keezar
  • 83
  • 1
  • 4
0
votes
1 answer

Duplicate File Pointer at the same position

Hy everyone, I've this code: int lenInput; char input[64], buffer[512], temp[512], *ret, tagName[] = "", tagItem[] = "
Federico Cuozzo
  • 363
  • 1
  • 7
  • 20
0
votes
1 answer

How to ignore empty pipes in CHILD process?

I am using a subroutine named read_from_pipe in my child process as below to read whatever is in the pipe and display it: void read_from_pipe(int fileDescriptr) { FILE *stream; int c; if (fileDesc_Is_Valid(fileDescriptr) == TRUE) { …
Bababarghi
  • 571
  • 1
  • 4
  • 23
0
votes
1 answer

QFile/FILE* : How to properly close the handle?

I need to open files with QFile and QString for multilingual without hair pulling. But I also need to manage the data of those files through the std::stream API. As many suggest, I used std::fstream stdFile(fdopen(qtFile.handle(), mode)); to do…
agrum
  • 407
  • 2
  • 16
0
votes
1 answer

Can a descriptor created by socket() be mapped to a memory buffer?

Is there a way to map a descriptor created by socket() to a memory buffer? The reason why I am looking for this is because I want to make an existing application to read from the memory buffer I created instead of its associated TCP buffer. I…
1
2