9 # supress VMS whinging about bad execs.
10 use vmsish qw(hushed);
12 $| = 1; # flush stdout
14 $ENV{LC_ALL} = 'C'; # Forge English error messages.
15 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
17 my $Is_VMS = $^O eq 'VMS';
21 my $Perl = which_perl();
25 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
27 my $tnum = curr_test();
28 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
30 is( $exit, 0, ' exited 0' );
33 my $tnum = curr_test();
34 $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
36 is( $exit, 0, ' exited 0' );
38 # On VMS you need the quotes around the program or it won't work.
39 # On Unix its the opposite.
40 my $quote = $Is_VMS ? '"' : '';
42 $exit = system $Perl, '-le',
43 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
45 is( $exit, 0, ' exited 0' );
48 # Some basic piped commands. Some OS's have trouble with "helpfully"
49 # putting newlines on the end of piped output. So we split this into
50 # newline insensitive and newline sensitive tests.
51 my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
52 $echo_out =~ s/\n\n/\n/g;
53 is( $echo_out, "ok\n", 'piped echo emulation');
56 # here we check if extra newlines are going to be slapped on
58 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
60 is( scalar `$Perl -e "print 'ok'"`,
61 "ok", 'no extra newlines on ``' );
63 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
64 "ok", 'no extra newlines on pipes');
66 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
67 "ok\n\n", 'doubled up newlines');
69 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
70 "ok\n", 'extra newlines on inside pipes');
72 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
73 "ok\n", 'extra newlines on outgoing pipes');
77 is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
79 my $exit_one = $Is_VMS ? 4 << 8 : 1 << 8;
80 is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
81 'Explicit exit of 1' );
84 $rc = system "lskdfj";
85 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256) ) {
86 print "# \$rc == $rc\n";
89 unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
90 $! == 13 or $! =~ /permission denied/i or
91 $! == 22 or $! =~ /invalid argument/ ) ) {
92 printf "# \$! eq %d, '%s'\n", $!, $!;
96 is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
97 is( <<`END`, "ok\n", '<<`HEREDOC`' );
98 $Perl -le "print 'ok'"
103 my $tnum = curr_test();
104 if( $^O =~ /Win32/ ) {
105 print "not ok $tnum - exec failure doesn't terminate process # TODO Win32 exec failure waits for user input\n";
110 ok( !exec("lskdjfalksdjfdjfkls"),
111 "exec failure doesn't terminate process");
114 my $test = curr_test();
115 exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
116 fail("This should never be reached if the exec() worked");