12 if (eval 'require VMS::Feature') {
13 $vms_exit_mode = !(VMS::Feature::current("posix_exit"));
15 my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
16 my $env_posix_ex = $ENV{'PERL_VMS_POSIX_EXIT'} || '';
17 my $unix_rpt = $env_unix_rpt =~ /^[ET1]/i;
18 my $posix_ex = $env_posix_ex =~ /^[ET1]/i;
19 if (($unix_rpt || $posix_ex) ) {
28 # supress VMS whinging about bad execs.
29 use vmsish qw(hushed);
31 $| = 1; # flush stdout
33 $ENV{LC_ALL} = 'C'; # Forge English error messages.
34 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
36 my $Is_VMS = $^O eq 'VMS';
37 my $Is_Win32 = $^O eq 'MSWin32';
41 my $Perl = which_perl();
45 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
47 my $tnum = curr_test();
48 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
50 is( $exit, 0, ' exited 0' );
53 my $tnum = curr_test();
54 $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
56 is( $exit, 0, ' exited 0' );
58 # On VMS and Win32 you need the quotes around the program or it won't work.
59 # On Unix its the opposite.
60 my $quote = $Is_VMS || $Is_Win32 ? '"' : '';
62 $exit = system $Perl, '-le',
63 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
65 is( $exit, 0, ' exited 0' );
68 # Some basic piped commands. Some OS's have trouble with "helpfully"
69 # putting newlines on the end of piped output. So we split this into
70 # newline insensitive and newline sensitive tests.
71 my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
72 $echo_out =~ s/\n\n/\n/g;
73 is( $echo_out, "ok\n", 'piped echo emulation');
76 # here we check if extra newlines are going to be slapped on
78 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
80 is( scalar `$Perl -e "print 'ok'"`,
81 "ok", 'no extra newlines on ``' );
83 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
84 "ok", 'no extra newlines on pipes');
86 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
87 "ok\n\n", 'doubled up newlines');
89 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
90 "ok\n", 'extra newlines on inside pipes');
92 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
93 "ok\n", 'extra newlines on outgoing pipes');
97 $out = runperl(prog => 'print q{1234}');
98 is($out, "1234", 'ignore $/ when capturing output in scalar context');
103 is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
105 my $exit_one = $vms_exit_mode ? 4 << 8 : 1 << 8;
106 is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
107 'Explicit exit of 1' );
109 $rc = system { "lskdfj" } "lskdfj";
110 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256 or $rc == 512) ) {
111 print "# \$rc == $rc\n";
114 unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
115 $! == 13 or $! =~ /permission denied/i or
116 $! == 22 or $! =~ /invalid argument/i ) ) {
117 printf "# \$! eq %d, '%s'\n", $!, $!;
121 is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
122 is( <<`END`, "ok\n", '<<`HEREDOC`' );
123 $Perl -le "print 'ok'"
127 my $_ = qq($Perl -le "print 'ok'");
128 is( readpipe, "ok\n", 'readpipe default argument' );
132 my $tnum = curr_test();
133 if( $^O =~ /Win32/ ) {
134 print "not ok $tnum - exec failure doesn't terminate process " .
135 "# TODO Win32 exec failure waits for user input\n";
140 ok( !exec("lskdjfalksdjfdjfkls"),
141 "exec failure doesn't terminate process");
144 my $test = curr_test();
145 exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
146 fail("This should never be reached if the exec() worked");