perl:用stdin副本执行另一个程序

发布于 2025-02-04 05:16:36 字数 684 浏览 3 评论 0原文

我有一个重定向到其他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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2025-02-11 05:16:36

最简单的方法:

use IPC::Run qw( run );

run [ "run", "/bin/anotherscript.cgi" ], '<', \$buf;

The easiest way:

use IPC::Run qw( run );

run [ "run", "/bin/anotherscript.cgi" ], '<', \$buf;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文