Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write data into own stdin in Linux

Tags:

c++

linux

cgi

I want to debug my cgi script (C++) from IDE, so I would like to create a "debug mode": read file from disk, push it to own stdin, set some environment variables, that correspond this file and run the rest of the script as it was called by the web server. Is it possible and if it is, then how can I do that?

like image 691
Nemo Avatar asked Jun 20 '12 20:06

Nemo


People also ask

How do you submit an input to a running process?

It is possible to send input text to a running process without running the screen utility, or any other fancy utility. And it can be done by sending this input text to the process' standard input "file" /proc/PID#/fd/0 . However, the input text needs to be sent in a special way to be read by the process.

Can Stdin be closed?

you can just fclose(stdin), it will call close() on the file handle.


1 Answers

You can't "push to own stdin", but you can redirect a file to your own stdin.

freopen("myfile.txt","r",stdin);
like image 180
J-16 SDiZ Avatar answered Oct 26 '22 04:10

J-16 SDiZ