Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing data do stdin

Status
Not open for further replies.

tokra

Technical User
Feb 20, 2003
45
0
0
GB
I'm trying to make a cgi program that will clean up and validate the requests before passing them on to the appropriate script. After a post, how do I put the string back into stdin so a program that I call using system will have it waiting for it?

WR
 
when a console program is ran by another console program it inherits the console, so, just use cout or printf functions and everything will be fine.

Ion Filipski
1c.bmp
 
How do you use cout to write to stdin rather than stdout?

WR
 
sorry, I was not attentive. I think you can use fwrite and fprintf with stdin as a file pointer.

Ion Filipski
1c.bmp
 
I tracked down a solution here is the code the demonstrates it.

Code:
#include <iostream>
#include <stdio.h>
#include <process.h>


int _tmain(int argc, _TCHAR* argv[])
{
	std::cout<<&quot;Items written to stdin:&quot;<<fwrite(&quot;test\n&quot;,1,5,stdin)<<std::endl;

	FILE* out;
	out=_popen(&quot;cmd&quot;,&quot;w&quot;);
	std::cout<<&quot;Items written to console:&quot;<<fwrite(&quot;test\n&quot;,1,5,out)<<std::endl;

	
	return 0;
}

WR
 
We can't use fprintf etc to write to stdin. C-stream stdin is read-only. Check return code from fprintf(stdin,...) - it's -1 (error;).
tokra wants a filter. It's impossible to do it with brute force...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top