- 论坛徽章:
- 0
|
本帖最后由 黑色阳光_cu 于 2010-08-15 10:24 编辑
- #!/bin/env perl
- use strict;
- use warnings;
- open(PIPE, "-|", "ls");
- print <PIPE>;
复制代码- #!/bin/env perl
- use strict;
- use warnings;
- substr($^O, 0, 2) ne "MS" or die "Cannot running undef Windows!\n";
- defined (my $pid = open(PIPE, "-|")) or die "Fork fail!\n";
- if ($pid != 0)
- {
- print <PIPE>;
- waitpid($pid, 0);
- }
- else
- {
- exec("ls");
- exit(1);
- }
复制代码
- #!/bin/env perl
- use strict;
- use warnings;
- substr($^O, 0, 2) ne "MS" or die "Cannot running undef Windows!\n";
- pipe(PIPE, W);
- defined (my $pid = fork()) or die "Fork fail!\n";
- if ($pid != 0)
- {
- close W;
- print <PIPE>;
- waitpid($pid, 0);
- }
- else
- {
- close PIPE;
- open(STDERR, ">&", *STDOUT);
- open(STDOUT, ">&", *W);
- close W;
- exec("ls");
- exit(1);
- }
复制代码 |
|