perl:用stdin副本执行另一个程序
我有一个重定向到其他Perl CGI脚本的PERL CGI脚本。将哪些脚本重定向到,取决于用“帖子”发布的数据内容。
因此,我的重定向脚本读取stdin
:
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
检查已发布的数据,然后重定向到另一个CGI脚本:
`run /bin/anotherscript.cgi`
然后,此脚本需要原始发布的数据,因此它还读取stdin
。但是到那时,它已经被阅读了,因为它已经被阅读。现在,我知道一种解决方案是将原始内容写入文件,然后将此文件用作第二个脚本的输入:
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
open( DATA, ">in.txt" );
print DATA $buffer;
close( DATA );
`run /bin/anotherscript.cgi < in.txt`
现在,这是在与许多用户的网站上。因此,我需要创建唯一的文件名,并确保之后一切都清理了。弄乱事物的潜力很大。
所以我想知道是否还有另一种方法?我可以将数据“将”数据推回STDIN吗?还是有一种更直接的方法将数据输送到新脚本?
I have a Perl CGI script that redirects to other Perl CGI scripts. Which script is redirected to, depends on the contents of data posted with "POST".
So my redirect script reads STDIN
:
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
examines the posted data, then redirects to another CGI script:
`run /bin/anotherscript.cgi`
This script then needs the original posted data so it also reads STDIN
. But by then it's empty since it has already been read. Now I know that one solution would be to write the original contents to a file, then use this file as input for the second script:
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
open( DATA, ">in.txt" );
print DATA $buffer;
close( DATA );
`run /bin/anotherscript.cgi < in.txt`
Now the problem with this is that this is on a website with many users. So I would need to create unique filenames, and make sure everything is nicely cleaned up afterwards. The potential to make a mess of things, is big.
So I was wondering if there's another way to do this? Can I "push" data back to STDIN? Or is there a more direct way to pipe data to the new script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法:
The easiest way: